Logo

dev-resources.site

for different kinds of informations.

Why I am unable to assert that method has been called on my mocked service?

Published at
1/30/2023
Categories
help
php
phpunit
testing
Author
pcmagas
Categories
4 categories in total
help
open
php
open
phpunit
open
testing
open
Author
7 person written this
pcmagas
open
Why I am unable to assert that method has been called on my mocked service?

Can you help me with this question?

I have made a simple class named MyService

namespace App\Services
class MyService
{

    private $anotherService;

    public function setService(AnotherService $anotherService)
    {
        $this->anotherService = $anotherService;
    }

    public function getService()
    {
        if(empty($this->anotherService)){
            $this->setService(new AnotherService());
        }

        return $this->anotherService;
    }

    public function call()
    {
        $anotherService = $this->getService();

        $anotherService->SetXY(5,10);
    }
}

As you can se via…

phpunit Article's
30 articles in total
Favicon
6 Steps to Master PHPUnit Testing with Ease!
Favicon
Mastering Unit Testing in PHP: Tools, Frameworks, and Best Practices
Favicon
PHP: Should I mock or should I go?
Favicon
Focusing your tests on the domain. A PHPUnit example
Favicon
Understanding Mock Objects in PHPUnit Testing
Favicon
Wrote a book (And it is not about coding, and yeap it is in Greek)
Favicon
How to run a phpunit unit test with a specific dataset
Favicon
Test Your DOM in Laravel with PHPUnit
Favicon
PHP: Mocking Closures and performing assertions
Favicon
Run PHPUnit locally in your WordPress Plugin with DDEV
Favicon
Setting up for Drupal's Functional JavaScript tests
Favicon
Fix Memory Exhausted Issue in Laravel Tests
Favicon
Another way to create test module configuration
Favicon
Testando filas em projetos Laravel
Favicon
Checklist to Become Software Developer
Favicon
Chat : Test unitaire sur des méthodes privées
Favicon
Chat: Unit test of private methods
Favicon
Upgrading to Laravel 10, PHPUnit 10, and Pest 2
Favicon
Testing an external api using PHPUnit
Favicon
Installing PHP Unit
Favicon
Code coverage for PHPUnit in VSCode
Favicon
Behavior-Driven Testing with PHP and PHPUnit
Favicon
Run Laravel test multiple times
Favicon
Using PHP anonymous classes to test collection services
Favicon
Test coverage: did you set Xdebug's coverage mode?
Favicon
Using github actions to execute your PHP tests after every push
Favicon
Writing a basic Feature Test with PhpUnit in Laravel
Favicon
Fix Symfony tests with PHPUnit 10
Favicon
The most efficient way to debug problems with PHPUnit mocks
Favicon
Why I am unable to assert that method has been called on my mocked service?

Featured ones: