/** @test */ public function shouldCallLimitAndCountWithUserObject() { $voter = new ResourceLimitVoter(['supportedClass' => '\\Aeris\\ZendRestModuleTest\\RestTestModule\\Model\\Animal', 'supportsResource' => Spy::returns(true), 'limit' => $limit = Spy::returns(100), 'count' => $count = Spy::returns(200)]); $user = self::Identity(['foo']); $voter->vote(self::Token(['getUser' => $user]), new Animal(), ['create']); $isUser = function ($arg) { return in_array('foo', $arg->getRoles()); }; $limit->shouldHaveBeenCalled()->with(M::on($isUser)); $count->shouldHaveBeenCalled()->with(M::on($isUser)); }
/** * @test * @expectedException \InvalidArgumentException */ public function method_times_shouldHandleNegativeArg() { Fn\times(-1, $spy = new Spy()); $spy->shouldNotHaveBeenCalled(); }
public static function returnsUsing(callable $cb) { $spy = new Spy(); $spy->andReturnUsing($cb); return $spy; }
/** @test */ public function returnsUsing_shouldCreateASpyWhichReturnsUsingTheCallable() { $spy = Spy::returnsUsing(function ($arg) { return strtoupper($arg); }); $this->assertEquals('FOO', $spy('foo')); }