getDependencies() public static method

Returns the dependencies for a test class or method.
public static getDependencies ( string $className, string $methodName ) : array
$className string
$methodName string
return array
Example #1
0
 /**
  * @constructor
  * @param string $class
  * @param string $name
  * @param string $path
  */
 public function __construct($class = '', $name = '', $path = '')
 {
     $this->initObjectManager();
     if (!$class || !class_exists($class, false)) {
         $this->addTest(self::warning(sprintf('Test Case Class is not valid or empty: "%s"', $class)));
         return;
     }
     if (!$name) {
         $this->addTest(self::warning(sprintf('Test Method Should be set for InjectableMethod class. Test Case Class: %s', $class)));
         return;
     }
     $this->setName($name);
     $arguments = ['class' => $class, 'path' => $path, 'name' => $name];
     $theClass = new \ReflectionClass($class);
     $method = $theClass->getMethod($name);
     if (!$this->isPublicTestMethod($method)) {
         return;
     }
     $methodName = $method->getName();
     $test = self::createTest($theClass, $methodName, $arguments);
     if ($test instanceof \PHPUnit_Framework_TestCase || $test instanceof InjectableMethod) {
         $test->setDependencies(\PHPUnit_Util_Test::getDependencies($class, $methodName));
     }
     $this->addTest($test, \PHPUnit_Util_Test::getGroups($class, $methodName));
     $this->testCase = true;
 }
Example #2
0
 protected function enhancePhpunitTest(\PHPUnit_Framework_TestCase $test)
 {
     $className = get_class($test);
     $methodName = $test->getName(false);
     $dependencies = \PHPUnit_Util_Test::getDependencies($className, $methodName);
     $test->setDependencies($dependencies);
     if ($test instanceof TestCaseFormat) {
         $test->getMetadata()->setDependencies($dependencies);
         $test->getMetadata()->setEnv(Annotation::forMethod($test, $methodName)->fetchAll('env'));
     }
 }
Example #3
0
 protected function enhancePhpunitTest(\PHPUnit_Framework_TestCase $test)
 {
     $className = get_class($test);
     $methodName = $test->getName(false);
     $dependencies = \PHPUnit_Util_Test::getDependencies($className, $methodName);
     $test->setDependencies($dependencies);
     if ($test instanceof UnitFormat) {
         $feature = $test->getName();
         $feature = preg_replace('/([A-Z]+)([A-Z][a-z])/', '\\1 \\2', $feature);
         $feature = preg_replace('/([a-z\\d])([A-Z])/', '\\1 \\2', $feature);
         $test->getMetadata()->setFeature(strtolower($feature));
         $test->getMetadata()->setDependencies($dependencies);
         $test->getMetadata()->setEnv(Annotation::forMethod($test, $methodName)->fetchAll('env'));
     }
 }
Example #4
0
 /**
  * @param ReflectionClass  $class
  * @param ReflectionMethod $method
  */
 protected function addTestMethod(ReflectionClass $class, ReflectionMethod $method)
 {
     if (!$this->isTestMethod($method)) {
         return;
     }
     $name = $method->getName();
     if (!$method->isPublic()) {
         $this->addTest(self::warning(sprintf('Test method "%s" in test class "%s" is not public.', $name, $class->getName())));
         return;
     }
     $test = self::createTest($class, $name);
     if ($test instanceof PHPUnit_Framework_TestCase || $test instanceof PHPUnit_Framework_TestSuite_DataProvider) {
         $test->setDependencies(PHPUnit_Util_Test::getDependencies($class->getName(), $name));
     }
     $this->addTest($test, PHPUnit_Util_Test::getGroups($class->getName(), $name));
 }
Example #5
0
 public function testParseAnnotationThatIsOnlyOneLine()
 {
     $this->assertEquals(array('Bar'), PHPUnit_Util_Test::getDependencies(get_class($this), 'methodForTestParseAnnotationThatIsOnlyOneLine'));
 }
Example #6
0
 protected function createTestFromCestMethod($cestInstance, $methodName, $file)
 {
     if (strpos($methodName, '_') === 0 or $methodName == '__construct') {
         return null;
     }
     $testClass = get_class($cestInstance);
     $cest = new Cest();
     $cest->configName($methodName)->configFile($file)->config('testClassInstance', $cestInstance)->config('testMethod', $methodName)->initConfig();
     $cest->getScenario()->env(Annotation::forMethod($testClass, $methodName)->fetchAll('env'));
     $cest->setDependencies(\PHPUnit_Util_Test::getDependencies($testClass, $methodName));
     return $cest;
 }
Example #7
0
 public function testParseAnnotation()
 {
     $this->assertEquals(array('Foo', 'ほげ'), PHPUnit_Util_Test::getDependencies(get_class($this), 'methodForTestParseAnnotation'));
 }
 /**
  * Takes a test and adds its dependencies
  *
  * @param PHPUnit_Framework_Test $test Object. A Test can be run and collect its results
  * @param string $className  Name of class what loaded to parsing and execute
  * @param string $methodName Name of method what loaded from class to adding dependencies
  *
  * @return void
  */
 public static function addTestDependencies(PHPUnit_Framework_Test $test, $className, $methodName)
 {
     if ($test instanceof PHPUnit_Framework_TestCase || $test instanceof PHPUnit_Framework_TestSuite_DataProvider) {
         $test->setDependencies(PHPUnit_Util_Test::getDependencies($className, $methodName));
     }
     return $test;
 }
Example #9
0
 protected function createTestFromCestMethod($cestInstance, $methodName, $file)
 {
     if (strpos($methodName, '_') === 0 || $methodName == '__construct') {
         return null;
     }
     $testClass = get_class($cestInstance);
     $cest = new Cest();
     $cest->configName($methodName)->configFile($file)->config('testClassInstance', $cestInstance)->config('testMethod', $methodName);
     $cest->setDependencies(\PHPUnit_Util_Test::getDependencies($testClass, $methodName));
     return $cest;
 }
Example #10
0
 protected function createTestFromCestMethod($cestInstance, $methodName, $file)
 {
     $testClass = get_class($cestInstance);
     if (strpos($methodName, '_') === 0) {
         return;
     }
     $guy = $this->settings['namespace'] ? $this->settings['namespace'] . '\\Codeception\\' . $this->settings['class_name'] : $this->settings['class_name'];
     $target = $testClass . '::' . $methodName;
     $cest = new TestCase\Cest($this->dispatcher, array('name' => $target, 'instance' => $cestInstance, 'method' => $methodName, 'file' => $file, 'bootstrap' => $this->settings['bootstrap'], 'guy' => $guy));
     $cest->setDependencies(\PHPUnit_Util_Test::getDependencies($testClass, $methodName));
     $cest->preload();
     return $cest;
 }
 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);
 }
Example #12
0
 protected function createTestFromCestMethod($cestInstance, $methodName, $file, $guy)
 {
     $testClass = get_class($cestInstance);
     if (strpos($methodName, '_') === 0) {
         return;
     }
     $overriddenGuy = Annotation::forMethod($testClass, $methodName)->fetch('guy');
     if (!$overriddenGuy) {
         $overriddenGuy = Annotation::forClass($testClass)->fetch('guy');
     }
     if ($overriddenGuy) {
         $guy = $overriddenGuy;
     }
     $cest = new TestCase\Cest($this->dispatcher, array('name' => $methodName, 'instance' => $cestInstance, 'method' => $methodName, 'file' => $file, 'bootstrap' => $this->settings['bootstrap'], 'guy' => $guy));
     $cest->getScenario()->env(Annotation::forMethod($testClass, $methodName)->fetchAll('env'));
     $cest->getScenario()->groups(\PHPUnit_Util_Test::getGroups($testClass, $methodName));
     $cest->setDependencies(\PHPUnit_Util_Test::getDependencies($testClass, $methodName));
     $cest->preload();
     return $cest;
 }