/** @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));
 }
Exemple #2
0
 /** @test */
 public function method_find()
 {
     $oneThroughTen = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
     $moreThanFive = Spy::returnsUsing(function ($n) {
         return $n > 5;
     });
     $this->assertEquals(6, Fn\find($oneThroughTen, $moreThanFive), 'Should return the first value to pass the predicate');
     // Should only call predicate until value is found (for performance)
     $moreThanFive->shouldHaveBeenCalled()->times(6);
     $this->assertNull(Fn\find([1, 2, 3], $moreThanFive), 'Should return null if none match.');
     $this->assertNull(Fn\find([], Fn\always()), 'Should return null if collection is empty');
     $spy = Spy::returns(true);
     $this->assertEquals('bar', Fn\find(['foo' => 'bar'], $spy), 'Should work with associateive arrays');
     // Should call spy with ($val, $key);
     $spy->shouldHaveBeenCalled()->with('bar', 'foo');
 }
Exemple #3
0
 /** @test */
 public function returns_shouldCreateASpyWhichReturnTheValue()
 {
     $spy = Spy::returns('foo');
     $this->assertEquals('foo', $spy());
 }