vendredi 9 novembre 2018

Mockery params are passed to function

I have same problem with testing

 public function testReturnUser(){
        $faker = Factory::create();
        $user = new User($faker->userName, $faker->email);

        $mockFinder = \Mockery::mock(ClassFinder::class);
        $mockFinder->shouldReceive('find')
            ->with(User::class, 1)
            ->andReturn($user);
        $helper = new Helper($mockFinder);
        $this->assertEquals([$user], $helper->getMethod(User::class));
    }

and in Helper class

class Helper {
   private $finder;
   public function __constructor(ClassFinder $finder){
      $this->finder = $finder;
   }
   public function getMethod(string $className, array $data =[]){
      return $this->finder->find($className, $data['id']);
   }
}

So problem is when i call getMethod without second optional parameter and run test I getting that $data['id'] is invalid index, although i pass params to Mock object. So if someone knows why this is happend?

Aucun commentaire:

Enregistrer un commentaire