mercredi 23 août 2017

How to get number of a determined called to method in PHPUnit

Currently I'm using strings to specifies where fail my test, like this:

In the first call to 'XY' method, the first parameter:

so, want to get the number of call with phpunit.

In short, I want instead 'first, second, third ...' a cardinal number, but given for phpunit (better)

public function testExample() {

        $test = $this;

        $this->myClass->expects($this->exactly(2))
                ->method('methodOne')
                ->withConsecutive(
                    [
                        $this->callback(function ($arg ) use ($test) {
                                $part = 'In the first call to methodOne method, the first parameter: ';
                                $test->assertThat($arg, $this->logicalAnd(
                                            $this->equalTo('example1')
                                        ),$part .'is not equal to "example1" '
                                );//assertThat
                                return true;
                        }),                                                                                                                          
                    ],
                    [
                        $this->callback(function ($arg) use ($test) {
                                $part = 'In the first call to methodOne method, the first parameter: ';
                                $test->assertThat($arg, $this->logicalAnd(
                                            $this->equalTo('example2')
                                        ),$part .'is not equal to "example2"'
                                );//assertThat
                                return true;
                        }),                     
                    ]
                )
                ->will($this->returnSelf());
}

I hope our help ! thanks for your attention.

Aucun commentaire:

Enregistrer un commentaire