Exemplo n.º 1
0
 /**
  * Create a new mock of the curlbuilder and return
  * the given filename as content
  *
  * @access public
  * @param  PHPUnit_Framework_TestCase   $instance
  * @return mock
  */
 public static function create($instance)
 {
     $reflection = new \ReflectionMethod($instance, $instance->getName());
     $doc_block = $reflection->getDocComment();
     $responsefile = self::parseDocBlock($doc_block, '@responsefile');
     $responsecode = self::parseDocBlock($doc_block, '@responsecode');
     $defaultheaders = array("X-Ratelimit-Limit" => "1000", "X-Ratelimit-Remaining" => "998", "X-Varnish" => "4059929980");
     $skipmock = self::parseDocBlock($doc_block, '@skipmock');
     if (empty($responsecode)) {
         $responsecode = [201];
     }
     if (empty($responsefile)) {
         $responsefile = [$instance->getName()];
     }
     // Setup Curlbuilder mock
     $curlbuilder = $instance->getMockBuilder("\\DirkGroenen\\Pinterest\\Utils\\CurlBuilder")->getMock();
     $curlbuilder->expects($instance->any())->method('create')->will($instance->returnSelf());
     // Build response file path
     $responseFilePath = __DIR__ . '/../responses/' . (new \ReflectionClass($instance))->getShortName() . '/' . $responsefile[0] . ".json";
     if (file_exists($responseFilePath)) {
         $curlbuilder->expects($instance->once())->method('execute')->will($instance->returnValue(file_get_contents($responseFilePath)));
     }
     $curlbuilder->expects($instance->any())->method('getInfo')->will($instance->returnValue($responsecode[0]));
     return $curlbuilder;
 }
Exemplo n.º 2
0
 /**
  * Determine the "full" test name (including the suite name if it is set)
  *
  * @param \PHPUnit_Framework_TestCase $test
  * @return string
  */
 private function getCurrentTestName(\PHPUnit_Framework_TestCase $test)
 {
     if (null === $this->currentSuite) {
         return $test->getName(true);
     }
     return $this->currentSuite->getName() . '::' . $test->getName(true);
 }
Exemplo n.º 3
0
 /**
  * Check whether test case is matched to specified object
  *
  * @param string $value
  * @return bool|null
  */
 protected function objectMatch($value)
 {
     if (!$this->testCase instanceof Injectable) {
         return null;
     }
     $arguments = $this->objectManager->prepareArguments($this->testCase, $this->testCase->getName(false));
     foreach ($arguments as $argument) {
         if ($argument instanceof $value) {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 4
0
 /**
  * Create a new mock of the curlbuilder and return 
  * the given filename as content
  * 
  * @access public
  * @param  PHPUnit_Framework_TestCase   $instance
  * @return mock
  */
 public static function create($instance)
 {
     $reflection = new \ReflectionMethod($instance, $instance->getName());
     $doc_block = $reflection->getDocComment();
     $responsefile = self::parseDocBlock($doc_block, '@responsefile');
     $responsecode = self::parseDocBlock($doc_block, '@responsecode');
     if (empty($responsecode)) {
         $responsecode = [201];
     }
     if (empty($responsefile)) {
         $responsefile = [$instance->getName()];
     }
     // Setup Curlbuilder mock
     $curlbuilder = $instance->getMockBuilder("\\DirkGroenen\\Pinterest\\Utils\\CurlBuilder")->getMock();
     $curlbuilder->expects($instance->once())->method('create')->will($instance->returnSelf());
     $curlbuilder->expects($instance->once())->method('execute')->will($instance->returnValue(file_get_contents(__DIR__ . '/../responses/' . (new \ReflectionClass($instance))->getShortName() . '/' . $responsefile[0] . ".json")));
     $curlbuilder->expects($instance->any())->method('getInfo')->will($instance->returnValue($responsecode[0]));
     return $curlbuilder;
 }
Exemplo n.º 5
0
 public static function runTest(\PHPUnit_Framework_TestCase $test)
 {
     if ($test->getName(false) === NULL) {
         throw new \PHPUnit_Framework_Exception('PHPUnit_Framework_TestCase::$name must not be NULL.');
     }
     try {
         $class = new \ReflectionClass($test);
         $method = $class->getMethod($test->getName(false));
         $methodName = $method->getName();
         $instance = new static();
         $instance->setTest($test);
         $instance->setClass($class);
         $instance->setMethod($method);
         $instance->cleanUpClass();
         $phpSpock = $instance->createPhpSpockInstance();
         $assertionCount = $phpSpock->runWithAdapter($instance, array($test, $methodName));
         $test->addToAssertionCount($assertionCount);
     } catch (\ReflectionException $e) {
         $test->fail($e->getMessage());
     } catch (\Exception $e) {
         $expectedExceptionClass = $test->getExpectedException();
         if (!$e instanceof \PHPUnit_Framework_IncompleteTest && !$e instanceof \PHPUnit_Framework_SkippedTest && is_string($test->getExpectedException()) && $e instanceof $expectedExceptionClass) {
             if (isset($methodName)) {
                 $expectedException = self::getExpectedExceptionFromAnnotation($test, $methodName);
                 if (is_string($expectedException['message']) && !empty($expectedException['message'])) {
                     $test->assertContains($expectedException['message'], $e->getMessage());
                 }
                 if (is_int($expectedException['code']) && $expectedException['code'] !== 0) {
                     $test->assertEquals($expectedException['code'], $e->getCode());
                 }
                 $test->addToAssertionCount(1);
                 return;
             }
         } else {
             throw $e;
         }
     }
 }
Exemplo n.º 6
0
 /**
  * @param \PHPUnit_Framework_TestCase $testCase
  */
 private function setUpContext(\PHPUnit_Framework_TestCase $testCase)
 {
     $testMethodArguments = array();
     $reflectionMethod = new \ReflectionMethod($testCase, $testCase->getName(false));
     $annotationReader = AnnotationReaderFactory::getAnnotationReader();
     $annotations = $annotationReader->getMethodAnnotations($reflectionMethod);
     foreach ($annotations as $i => $annotation) {
         if ($annotation instanceof Arrange) {
             $arrangeOutput = $this->runAnnotations($testCase, $annotation, $i);
             if ($arrangeOutput !== null) {
                 $testMethodArguments[] = $arrangeOutput;
             }
         }
     }
     $testCase->setDependencyInput($testMethodArguments);
 }
 /**
  * @param \PHPUnit_Framework_TestCase $test
  * @return array
  */
 private function getArrangeLines(\PHPUnit_Framework_TestCase $test)
 {
     $arranges = [];
     $annotationReader = AnnotationReaderFactory::getAnnotationReader();
     foreach (ArrangeListener::$inputs[$test->getName(true)] as $i => $arrangeMethods) {
         foreach ($arrangeMethods as $arrangeMethod => $arguments) {
             try {
                 $describe = $this->getArrangeDescription($test, $annotationReader, $arrangeMethod);
                 $arranges[] = $this->getArrangeLine($describe, $arguments);
             } catch (\DomainException $ex) {
                 continue;
             }
         }
     }
     return $arranges;
 }
Exemplo n.º 8
0
 /**
  * Prints the message for skipping tests.
  *
  * @param string $message Text of skip condition.
  * @param PHPUnit_Framework_TestCase $test the test method skipped
  * @return void
  */
 public function paintSkip($message, $test)
 {
     echo "<li class='skipped'>\n";
     echo "<span>Skipped</span> ";
     echo $test->getName() . ': ' . $this->_htmlEntities($message->getMessage());
     echo "</li>\n";
 }
Exemplo n.º 9
0
 /**
  * Creates a unique string ID for $test that can be used in URLs.
  *
  * @param PHPUnit_Framework_TestCase $test a test for which to create an ID
  *
  * @return string a unique ID for $test, not htmlspecialchared or URL-encoded yet
  */
 protected function createTestId(PHPUnit_Framework_TestCase $test)
 {
     $testNameParts = explode(' ', $test->getName());
     // This is quite a hack.
     // @see http://forge.typo3.org/issues/11735
     if (strpos($this->currentTestCaseName, '::') !== false) {
         $result = $testNameParts[0] . '(' . $this->getTestCaseName() . ')';
     } else {
         $result = $this->getTestCaseName() . '::' . $testNameParts[0];
     }
     return $result;
 }
 private static function addGeneratedTestTo(PHPUnit_Framework_TestSuite $suite, PHPUnit_Framework_TestCase $test, $classGroups)
 {
     list($methodName, ) = explode(' ', $test->getName());
     $test->setDependencies(PHPUnit_Util_Test::getDependencies(get_class($test), $methodName));
     $suite->addTest($test, $classGroups);
 }
 private function getTime(TestCase $test)
 {
     $name = $test->getName();
     $class = get_class($test);
     foreach ($this->timings as $timing) {
         if ($timing['class'] === $class && $timing['test'] === $name) {
             return $timing['time'];
         }
     }
 }
 public function getName($withDataSet = TRUE)
 {
     return $this->suite->getName() . ' - ' . parent::getName($withDataSet);
 }
Exemplo n.º 13
0
 /**
  * @param \PHPUnit_Framework_TestCase $testCase
  * @return bool
  */
 private function hasTestCaseDataSet(\PHPUnit_Framework_TestCase $testCase)
 {
     return $testCase->getName(false) === $testCase->getName(true);
 }
Exemplo n.º 14
0
 /**
  * Determines which location shall be fetched from the list of configured locations.
  *
  * @param \PHPUnit_Framework_TestCase $test
  *
  * @return string
  */
 protected function getRunlevel(\PHPUnit_Framework_TestCase $test)
 {
     return $this->extractRunlevelFromTestName($test->getName());
 }