Exemple #1
0
 public function testCanOverrideExpectedParametersOfInternalPHPClassesToPreserveRefs()
 {
     if (!class_exists('MongoCollection', false)) {
         $this->markTestSkipped('ext/mongo not installed');
     }
     ehough_mockery_Mockery::getConfiguration()->setInternalClassMethodParamMap('MongoCollection', 'insert', array('&$data', '$options'));
     $m = $this->container->mock('MongoCollection');
     $m->shouldReceive('insert')->with(ehough_mockery_Mockery::on(function (&$data) {
         $data['_id'] = 123;
         return true;
     }), ehough_mockery_Mockery::type('array'));
     $data = array('a' => 1, 'b' => 2);
     $m->insert($data, array());
     $this->assertTrue(isset($data['_id']));
     $this->assertEquals(123, $data['_id']);
     $this->container->mockery_verify();
     ehough_mockery_Mockery::resetContainer();
 }
Exemple #2
0
 public function testAnExampleWithSomeExpectationAmendsOnCallCounts()
 {
     $service = $this->container->mock('MyService');
     $service->shouldReceive('login')->with('user', 'pass')->once()->andReturn(true);
     $service->shouldReceive('hasBookmarksTagged')->with('php')->once()->andReturn(false);
     $service->shouldReceive('addBookmark')->with('/^http:/', ehough_mockery_Mockery::type('string'))->times(3)->andReturn(true);
     $service->shouldReceive('hasBookmarksTagged')->with('php')->twice()->andReturn(true);
     $this->assertTrue($service->login('user', 'pass'));
     $this->assertFalse($service->hasBookmarksTagged('php'));
     $this->assertTrue($service->addBookmark('http://example.com/1', 'some_tag1'));
     $this->assertTrue($service->addBookmark('http://example.com/2', 'some_tag2'));
     $this->assertTrue($service->addBookmark('http://example.com/3', 'some_tag3'));
     $this->assertTrue($service->hasBookmarksTagged('php'));
     $this->assertTrue($service->hasBookmarksTagged('php'));
     $this->container->mockery_verify();
 }