jeudi 14 janvier 2021

how to properly use mockbuilder from phpunit?

I'm trying to mock one of my class using phpunit mockbuilder but I only want the 'index' method. But When I try with the code below, the var_dump indicates I have all the methods from my class in the mock?? Is that normal? What am I doing wrong?

Thanks in advance.

public function setUp(): void
        {
            parent::setUp();
    
            $mockController = $this->getMockBuilder(MyClass::class)
                                    ->disableOriginalConstructor()
                                    ->disableOriginalClone()
                                    ->disableArgumentCloning()
                                    ->disallowMockingUnknownTypes()
                                    ->setMethods(['index'])
                                    ->getMock();
                                    
            var_dump(get_class_methods($mockController));
        }

Edit1: result of var_dump:

array(18) {
  [0]=>
  string(5) "index"
  [1]=>
  string(11) "__construct"
  [2]=>
  string(6) "launch"
  [3]=>
  string(8) "continue"
  [4]=>
  string(6) "setCss"
  [5]=>
  string(5) "setJs"
  [6]=>
  string(4) "meta"
  [7]=>
  string(6) "render"
  [8]=>
  string(14) "initController"
  [9]=>
  string(33) "__phpunit_initConfigurableMethods"
  [10]=>
  string(27) "__phpunit_setOriginalObject"
  [11]=>
  string(34) "__phpunit_setReturnValueGeneration"
  [12]=>
  string(30) "__phpunit_getInvocationHandler"
  [13]=>
  string(21) "__phpunit_hasMatchers"
  [14]=>
  string(16) "__phpunit_verify"
  [15]=>
  string(7) "expects"
  [16]=>
  string(6) "method"
  [17]=>
  string(7) "__clone"
}

Thanks





Aucun commentaire:

Enregistrer un commentaire