public function tearDown()
 {
     if ($container = m::getContainer()) {
         $this->addToAssertionCount($container->mockery_getExpectationCount());
     }
     parent::tearDown();
 }
Ejemplo n.º 2
0
 /**
  * Performs assertions shared by all tests of a test case. This method is
  * called before execution of a test ends and before the tearDown method.
  */
 protected function assertPostConditions()
 {
     parent::assertPostConditions();
     // Add Mockery expectations to assertion count.
     if (($container = Mock::getContainer()) !== null) {
         $this->addToAssertionCount($container->mockery_getExpectationCount());
     }
 }
Ejemplo n.º 3
0
 protected function setUp()
 {
     // We intentionally test the static container here. That is what the
     // listener will check.
     $this->container = \Mockery::getContainer();
     $this->listener = new \Mockery\Adapter\Phpunit\TestListener();
     $this->testResult = new \PHPUnit_Framework_TestResult();
     $this->test = new \Mockery_Adapter_Phpunit_EmptyTestCase();
     $this->test->setTestResultObject($this->testResult);
     $this->testResult->addListener($this->listener);
     $this->assertTrue($this->testResult->wasSuccessful(), 'sanity check: empty test results should be considered successful');
 }
 /**
  * After each test, perform Mockery verification tasks and cleanup the
  * statically stored Mockery container for the next test.
  *
  * @param  PHPUnit_Framework_Test $test
  * @param  float                  $time
  */
 public function endTest(\PHPUnit_Framework_Test $test, $time)
 {
     try {
         $container = \Mockery::getContainer();
         if ($container != null) {
             $expectation_count = $container->mockery_getExpectationCount();
             $test->addToAssertionCount($expectation_count);
         }
         \Mockery::close();
     } catch (\Exception $e) {
         $result = $test->getTestResultObject();
         $result->addError($test, $e, $time);
     }
 }
Ejemplo n.º 5
0
 /**
  * After each test, perform Mockery verification tasks and cleanup the
  * statically stored Mockery container for the next test.
  *
  * @param PHPUnit_Framework_Test $test        	
  * @param float $time        	
  */
 public function endTest(\PHPUnit_Framework_Test $test, $time)
 {
     try {
         $container = \Mockery::getContainer();
         // check addToAssertionCount is important to avoid mask test errors
         if ($container != null && method_exists($test, 'addToAssertionCount')) {
             $expectation_count = $container->mockery_getExpectationCount();
             $test->addToAssertionCount($expectation_count);
         }
         \Mockery::close();
     } catch (\Exception $e) {
         $result = $test->getTestResultObject();
         $result->addError($test, $e, $time);
     }
 }
Ejemplo n.º 6
0
 protected function verifyMockObjects()
 {
     $container = Mockery::getContainer();
     if (isset($container)) {
         $reflected_container = new ReflectionClass($container);
         $reflected_mocks = $reflected_container->getProperty('_mocks');
         $reflected_mocks->setAccessible(true);
         $mocks = $reflected_mocks->getValue($container);
         foreach ($mocks as $mock) {
             $reflected_mock = new ReflectionClass($mock);
             $reflected_expectations = $reflected_mock->getProperty('_mockery_expectations');
             $reflected_expectations->setAccessible(true);
             $expectations = $reflected_expectations->getValue($mock);
             foreach ($expectations as $director) {
                 $this->addToAssertionCount(count($director->getExpectations()));
             }
         }
         Mockery::close();
     }
     parent::verifyMockObjects();
 }
Ejemplo n.º 7
0
 public function tearDown()
 {
     $this->addToAssertionCount(Mockery::getContainer()->mockery_getExpectationCount());
     Mockery::close();
 }
Ejemplo n.º 8
0
 /**
  * Do not check assertions were executed when there are constrainted mocks
  */
 protected static function ignoreAssertionsWhenExpectations()
 {
     /** @var Mock $mock */
     foreach (\Mockery::getContainer()->getMocks() as $mock) {
         /** @var ExpectationDirector $expectationDirector */
         foreach ($mock->mockery_getExpectations() as $expectationDirector) {
             $expectations = $expectationDirector->getExpectations();
             if (method_exists($expectationDirector, 'getDefaultExpectations')) {
                 //mockery <=0.9.5 compatibility
                 $expectations = array_merge($expectations, $expectationDirector->getDefaultExpectations());
             }
             /** @var Expectation $expectation */
             foreach ($expectations as $expectation) {
                 if ($expectation->isCallCountConstrained()) {
                     Environment::$checkAssertions = FALSE;
                     return;
                 }
             }
         }
     }
 }