How to use PHPUnit to test a method that calls other methods of the same class but does not return a value

How do you write unit test for a method that calls other methods of the same class but does not return a value? (Say with PHPUnit.)

For example, suppose I have the following class:

class MyClass {

    public function doEverything() {

        $this->doA;
        $this->doB;
        $this->doC;

    }

    public function doA() {
        // do something, return nothing
    }

    public function doB() {
        // do something, return nothing
    }

    public function doC() {
        // do something, return nothing
    }

}

How would you test doEverything()?

EDIT:

I ask this because from what I read, it seems that almost every method should have its own dedicated unit test. Of course, you also have functional and integration tests, but these target routines, so to speak (not necessarily at the level of each method).

unit test, , " " unit test . /?

+4
2

! ! , - , - sibling . PHPUnit, .

, doEverything() , - :

public function testDoEverything()
{

    // Any methods not specified in setMethods will execute perfectly normally,
    // and any methods that ARE specified return null (or whatever you specify)
    $mock = $this->getMockBuilder('\MyClass')
        ->setMethods(array('doA', 'doB', 'doC'))
        ->getMock();

    // doA() should be called once
    $mock->expects($this->once())
         ->method('doA');

    // doB() should be called once
    $mock->expects($this->once())
         ->method('doB');

    // doC() should be called once
    $mock->expects($this->once())
         ->method('doC');

    // Call doEverything and see if it calls the functions like our
    // above written expectations specify
    $mock->doEverything();
}

! !

: Laravel Codeception...

Laravel Framework, Codeception, . Laravel Codeception, , , Laravel PHPUnit. unit.suite.yml, Laravel4, :

# Codeception Test Suite Configuration

# suite for unit (internal) tests.
class_name: UnitTester
modules:
    enabled: [Asserts, UnitHelper, Laravel4]

php codecept.phar build, .

+6

, , . , . , , - . , !

: , , .

, . - - . , - , .

- , . , . Test Driven Development , , .

+2

All Articles