示例#1
0
 /**
  * @param string $class
  * @param array $arguments
  * @return BlockInterface
  * @throws \UnexpectedValueException
  */
 public function create($class, array $arguments = [])
 {
     $object = $this->objectManager->create($class, $arguments);
     if (!$object instanceof BlockInterface) {
         throw new \UnexpectedValueException(sprintf('Block class "%s" has to implement \\Mtf\\Block\\BlockInterface interface.', $class));
     }
     return $object;
 }
示例#2
0
 /**
  * Get test suite
  *
  * @param string $class
  * @return InjectableTestCase|RegularTestCase
  */
 public function get($class)
 {
     $refClass = new \ReflectionClass($class);
     if ($refClass->isSubclassOf('Mtf\\TestCase\\Injectable')) {
         $object = $this->objectManager->get('Mtf\\TestSuite\\InjectableTestCase');
     } else {
         $object = $this->objectManager->create('Mtf\\TestSuite\\RegularTestCase');
     }
     return $object;
 }
示例#3
0
 /**
  * Returns instance of observer
  *
  * @param string $class
  * @return ObserverInterface
  * @throws \InvalidArgumentException
  */
 public function getObserver($class)
 {
     if (empty($this->observerPool[$class])) {
         $instance = $this->objectManager->create($class);
         if (!$instance instanceof ObserverInterface) {
             throw new \InvalidArgumentException(sprintf('Observer class %s should implement ObserverInterface.', $class));
         }
         $this->observerPool[$class] = $instance;
     }
     return $this->observerPool[$class];
 }
示例#4
0
 /**
  * Run a Mtf application
  *
  * @param $applicationName
  * @param array $arguments
  * @return mixed
  * @throws \DomainException
  */
 public function run($applicationName, array $arguments = array())
 {
     try {
         if (!$this->_locator) {
             $locatorFactory = new \Mtf\ObjectManagerFactory();
             $this->_locator = $locatorFactory->create();
         }
         return $this->_locator->create($applicationName, $arguments)->launch();
     } catch (\Exception $exception) {
         $message = "Error happened during application run.\n";
         $message .= $exception->getMessage();
         throw new \DomainException($message);
     }
 }
 /**
  * Initialize module filters and related data structures
  *
  * @return void
  */
 protected function init()
 {
     $moduleFilter = getenv(self::MODULE_FILTER);
     if (empty($moduleFilter)) {
         $this->moduleFilters = [];
         return;
     }
     $this->moduleFilters = array_map('trim', explode(',', $moduleFilter));
     if (empty($this->moduleFilters)) {
         return;
     }
     //
     $this->affectedModules = array_flip($this->moduleFilters);
     /** @var $constraintCrossReference \Mtf\Util\CrossModuleReference\Constraint */
     $constraintCrossReference = $this->objectManager->get('\\Mtf\\Util\\CrossModuleReference\\Constraint');
     /** @var $testStepCrossReference \Mtf\Util\CrossModuleReference\TestStep */
     $testStepCrossReference = $this->objectManager->get('\\Mtf\\Util\\CrossModuleReference\\TestStep');
     /** @var $pageCrossReference \Mtf\Util\CrossModuleReference\Page */
     $pageCrossReference = $this->objectManager->create('\\Mtf\\Util\\CrossModuleReference\\Page', ['constraintChecker' => $constraintCrossReference, 'modules' => $this->moduleFilters]);
     $crossModuleReferenceCheckers = [$constraintCrossReference, $testStepCrossReference, $pageCrossReference];
     $this->affectedTestCases = [];
     foreach ($crossModuleReferenceCheckers as $crossModuleReferenceChecker) {
         foreach ($this->moduleFilters as $module) {
             $affectedTestCases = $crossModuleReferenceChecker->getCrossModuleReference($module);
             $this->affectedTestCases = array_merge($this->affectedTestCases, $affectedTestCases);
         }
     }
 }
示例#6
0
 /**
  * @constructor
  * @param string $theClass
  * @param string $name
  */
 public function __construct($theClass = '', $name = '')
 {
     $this->initObjectManager();
     $this->appStateFactory = $this->objectManager->get('Mtf\\App\\State\\StateFactory');
     /** @var $applicationStateIterator \Mtf\Util\Iterator\ApplicationState */
     $applicationStateIterator = $this->objectManager->create('Mtf\\Util\\Iterator\\ApplicationState');
     while ($applicationStateIterator->valid()) {
         $appState = $applicationStateIterator->current();
         $callback = [$this, 'appStateCallback'];
         /** @var $suite \Mtf\TestSuite\TestCase */
         $suite = $this->objectManager->create('Mtf\\TestSuite\\TestCase', ['name' => $appState['name']]);
         $suite->setCallback($callback, $appState);
         $this->addTest($suite, \PHPUnit_Util_Test::getGroups(get_class($suite), $suite->getName()));
         $applicationStateIterator->next();
     }
     parent::__construct('Application State Runner');
 }
示例#7
0
 /**
  * Get list of variations table
  *
  * @return array
  */
 protected function getVariations()
 {
     self::$count = 0;
     $variations = [];
     /** @var $source \Mtf\Util\Iterator\Variation */
     $source = $this->objectManager->create('Mtf\\Util\\Iterator\\Variation', ['testCase' => $this->testCase]);
     if (count($source)) {
         while ($variation = $source->current()) {
             if (!$source->valid()) {
                 break;
             }
             ++self::$count;
             $variations[self::$count] = $variation;
             $source->next();
         }
     } else {
         $variations['Default'] = [];
     }
     return $variations;
 }
示例#8
0
 /**
  * @constructor
  * @param string $theClass
  * @param string $name
  */
 public function __construct($theClass = '', $name = '')
 {
     $this->initObjectManager();
     $this->testSuiteFactory = $this->objectManager->get('Mtf\\TestSuite\\TestSuiteFactory');
     /** @var $testIterator \Mtf\Util\Iterator\TestCase */
     $testIterator = $this->objectManager->create('Mtf\\Util\\Iterator\\TestCase');
     while ($testIterator->valid()) {
         $arguments = $testIterator->current();
         $class = $arguments['class'];
         $factory = $this->testSuiteFactory;
         $testCallback = $this->objectManager->create('Mtf\\TestSuite\\Callback', ['factory' => $factory, 'arguments' => $arguments, 'theClass' => $class]);
         $rule = $this->objectManager->get('Mtf\\TestRunner\\Rule\\SuiteComposite');
         $testCaseSuite = $this->testSuiteFactory->get($class);
         $allow = $rule->filterSuite($testCaseSuite);
         if ($allow) {
             $this->addTest($testCallback, \PHPUnit_Util_Test::getGroups($class));
         }
         $testIterator->next();
     }
     parent::__construct($name);
 }
示例#9
0
 /**
  * @constructor
  * @param string $class
  * @param string $name
  * @param string $path
  */
 public function __construct($class = '', $name = '', $path = '')
 {
     // we don't need parent class to collect tests, so don't call parent constructor
     $this->initObjectManager();
     $name = $name ? $name : $class;
     $this->setName($name);
     if (is_string($class) && class_exists($class, false)) {
         $arguments = ['class' => $class, 'path' => $path];
         $theClass = new \ReflectionClass($class);
         foreach ($theClass->getMethods() as $method) {
             if (!$this->isPublicTestMethod($method)) {
                 continue;
             }
             $_arguments = $arguments;
             $methodName = $method->getName();
             $_arguments['name'] = $methodName;
             $test = $this->objectManager->create('Mtf\\TestSuite\\InjectableMethod', $_arguments);
             $this->addTest($test, \PHPUnit_Util_Test::getGroups($class, $methodName));
         }
     }
     $this->testCase = true;
 }
示例#10
0
 /**
  * Prepare test suite and apply application state
  *
  * @return \Mtf\TestSuite\AppState
  */
 public function prepareSuite()
 {
     $this->init();
     return $this->objectManager->create('Mtf\\TestSuite\\AppState');
 }
示例#11
0
 /**
  * Create Event class object
  *
  * @param array $tags
  * @param array $subjects
  * @return \Mtf\System\Event\Event
  */
 public function create(array $tags, array $subjects)
 {
     return $this->objectManager->create('Mtf\\System\\Event\\Event', ['tags' => $tags, 'subjects' => $subjects]);
 }
示例#12
0
 /**
  * Create class via ObjectManager
  *
  * @param string $class
  * @param array $arguments
  * @return mixed
  */
 public function create($class, array $arguments = [])
 {
     $object = $this->objectManager->create($class, $arguments);
     $this->checkInterface($object, $class);
     return $object;
 }