Code to run before each test.

@param TestInterface $test
@throws ModuleException
6750
public function _before(TestInterface $test)
    {
        if (!extension_loaded('apc') && !extension_loaded('apcu')) {
            throw new ModuleException(
                __CLASS__,
                'The APC(u) extension not loaded.'
            );
        }

        if (!ini_get('apc.enabled') || (PHP_SAPI === 'cli' && !ini_get('apc.enable_cli'))) {
            throw new ModuleException(
                __CLASS__,
                'The "apc.enable_cli" parameter must be set to "On".'
            );
        }
    }
968704
public function prepareExecute(InputInterface $input)
    {
        $this->coverFishHelper = new CoverFishHelper();

        $phpUnitConfigFile = $input->getArgument('phpunit-config');
        if (false === empty($phpUnitConfigFile) &&
            false === $this->coverFishHelper->checkFileOrPath($phpUnitConfigFile)) {
            throw new \Exception(sprintf('phpunit config file "%s" not found! please define your phpunit.xml config file to use (e.g. tests/phpunit.xml)', $phpUnitConfigFile));
        }

        $testPathOrFile = $input->getOption('raw-scan-path');
        if (false === empty($testPathOrFile) &&
            false === $this->coverFishHelper->checkFileOrPath($testPathOrFile)) {
            throw new \Exception(sprintf('test path/file "%s" not found! please define test file path (e.g. tests/)', $testPathOrFile));
        }
    }
974477
final protected function assertClassImplementsInterface(string $interfaceName, string $className): void
    {
        $this->assertInterfaceExists($interfaceName);
        $this->assertClassExists($className);

        $reflection = new \ReflectionClass($className);

        self::assertTrue($reflection->implementsInterface($interfaceName), \sprintf(
            'Failed asserting that class "%s" implements interface "%s".',
            $className,
            $interfaceName
        ));
    }
1232869
public function beforeExample(ScenarioTested $event)
    {
        $this->currentTestcase = $this->currentTestsuite->addChild('testcase');
        $this->currentTestcase->addAttribute('name', $this->currentOutlineTitle . ' Line #' . $event->getScenario()->getLine());

        $this->testcaseTimer->start();
    }
345719
public function force(PHPUnit_Framework_TestCase $test)
    {
        if (!$test->hasFailed()) {
            return;
        }
        $testReflection = new ReflectionClass('PHPUnit_Framework_TestCase');
        $resultReflection = new ReflectionClass('PHPUnit_Framework_TestResult');

        $result = $this->getPropertyValue($testReflection, 'result', $test);
        $this
            ->forcePropertyValue($resultReflection, 'errors', array(), $result)
            ->forcePropertyValue($resultReflection, 'failures', array(), $result)
            ->forcePropertyValue($resultReflection, 'risky', array(), $result)
            ->forcePropertyValue($testReflection, 'status', PHPUnit_Runner_BaseTestRunner::STATUS_PASSED, $test)
            ->forcePropertyValue($testReflection, 'statusMessage', '', $test);
    }
465959
public function init(ServerContextInterface $serverContext)
    {
        try {
            // set the servlet context
            $this->serverContext = $serverContext;

            // initialize the servlet engine
            $this->initValves();
            $this->initHandlers();
            $this->initApplications();

        } catch (\Exception $e) {
            throw new ModuleException($e);
        }
    }
542778
public function addError(\PHPUnit_Framework_Test $test, \Exception $e, $time)
    {
        if (!$this->colors) {
            parent::addError($test, $e, $time);

            return;
        }

        $this->writeProgress(Coloring::magenta('E'));
        $this->lastTestFailed = true;
    }
778795
public function addWarning(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_Warning $e, $time)
    {
        $this->writeWarning($test, $e, $time);
    }
793699
public function addSkipped(Test $test)
    {
        $this->output->updateTable($test->pos->x, $test->pos->y, Graphite::MAGENTA);
        $this->skipped[] = $test;
    }
1128509
public function init(ModuleManagerInterface $manager)
    {
        if (!$manager instanceof ModuleManager) {
            $errMsg =sprintf('Module manager not implement %s', ModuleManager::class);
            throw new Exception\InvalidArgumentException($errMsg);
        }

        
        /** @var ServiceLocatorInterface $sm */
        $sm = $manager->getEvent()->getParam('ServiceManager');

        if (!$sm instanceof ServiceLocatorInterface) {
            $errMsg = sprintf('Service locator not implement %s', ServiceLocatorInterface::class);
            throw new Exception\InvalidArgumentException($errMsg);
        }
        /** @var ServiceListenerInterface $serviceListener */
        $serviceListener = $sm->get('ServiceListener');
        if (!$serviceListener instanceof ServiceListenerInterface) {
            $errMsg = sprintf('ServiceListener not implement %s', ServiceListenerInterface::class);
            throw new Exception\InvalidArgumentException($errMsg);
        }


        $serviceListener->addServiceManager(
            EntryNameResolverManagerInterface::class,
            EntryNameResolverManager::CONFIG_KEY,
            EntryNameResolverProviderInterface::class,
            'getEntryNameResolverConfig'
        );

    }
800720
public function beforeCompile(): void
	{
		// Breaks at other mode then CLI
		if (PHP_SAPI !== 'cli') return;

		$builder = $this->getContainerBuilder();

		// Verify that we have http.request
		if (!$builder->hasDefinition('http.request')) {
			throw new RuntimeException('Service http.request is needed');
		}

		$config = $this->validateConfig($this->defaults);
		$builder->getDefinition('http.request')
			->setFactory(Request::class, [
				new Statement(UrlScript::class, [$config['url']]),
				$config['query'],
				$config['post'],
				$config['files'],
				$config['cookies'],
				$config['headers'],
				$config['method'],
				$config['remoteAddress'],
				$config['remoteHost'],
				$config['rawBodyCallback'],
			]);
	}
577311
public static function setupVariables(string $testerDir): void
	{
		if (!is_dir($testerDir)) {
			die(sprintf('Provide existing folder, "%s" does not exist.', $testerDir));
		}

		// Base tester directory
		define('TESTER_DIR', realpath($testerDir));

		// Application directories
		define('APP_DIR', realpath(TESTER_DIR . '/../app'));
		define('WWW_DIR', realpath(TESTER_DIR . '/../www'));

		// Tester directories
		define('ENGINE_DIR', TESTER_DIR . '/engine');
		define('CASES_DIR', TESTER_DIR . '/cases');
		define('CASES_UNIT_DIR', TESTER_DIR . '/cases/unit');
		define('CASES_INTEGRATION_IDR', TESTER_DIR . '/cases/integration');

		// Temp, cache directories
		define('TMP_DIR', TESTER_DIR . '/tmp');
		define('TEMP_DIR', TMP_DIR . '/tests/' . getmypid() . '/' . md5(uniqid((string) microtime(true), true) . lcg_value() . mt_rand(0, 20) . microtime()));
		define('CACHE_DIR', TMP_DIR . '/cache');
		ini_set('session.save_path', TEMP_DIR);

		// Create folders
		clearstatcache(true, TMP_DIR);
		self::mkdir(TMP_DIR);
		clearstatcache(true, CACHE_DIR);
		self::mkdir(CACHE_DIR);
		clearstatcache(true, TEMP_DIR);
		self::mkdir(TEMP_DIR);
		clearstatcache(true, TEMP_DIR);
		self::purge(TEMP_DIR);
	}
298288
public function debugWebDriverLogs(TestInterface $test = null)
    {
        if (!isset($this->webDriver)) {
            $this->debug('WebDriver::debugWebDriverLogs method has been called when webDriver is not set');
            return;
        }
        try {
            // Dump out latest Selenium logs
            $logs = $this->webDriver->manage()->getAvailableLogTypes();
            foreach ($logs as $logType) {
                $logEntries = array_slice(
                    $this->webDriver->manage()->getLog($logType),
                    -$this->config['debug_log_entries']
                );

                if (empty($logEntries)) {
                    $this->debugSection("Selenium {$logType} Logs", " EMPTY ");
                    continue;
                }
                $this->debugSection("Selenium {$logType} Logs", "\n" . $this->formatLogEntries($logEntries));

                if ($logType === 'browser' && $this->config['log_js_errors']
                    && ($test instanceof ScenarioDriven)
                ) {
                    $this->logJSErrors($test, $logEntries);
                }
            }
        } catch (\Exception $e) {
            $this->debug('Unable to retrieve Selenium logs : ' . $e->getMessage());
        }
    }
74516
private function loadFixtures($test)
    {
        $this->debugSection('Fixtures', 'Loading fixtures');
        if (empty($this->loadedFixtures)
            && method_exists($test, $this->_getConfig('fixturesMethod'))
        ) {
            $connectionWatcher = new Yii2Connector\ConnectionWatcher();
            $connectionWatcher->start();
            $this->haveFixtures(call_user_func([$test, $this->_getConfig('fixturesMethod')]));
            $connectionWatcher->stop();
            $connectionWatcher->closeAll();
        }
        $this->debugSection('Fixtures', 'Done');
    }
1013013
public function addError(Test $test)
    {
        $this->output->updateTable($test->pos->x, $test->pos->y, Graphite::YELLOW);
        $this->errors[] = $test;
    }
473155
public function isEnqueued($test)
    {
        return
            $test->state == Constants::STATE_QUEUED
            &&
            QueueModel::where('test_id', $test->id)->first();
    }
483270
public function _after(TestInterface $test)
    {
        if ($this->config['reconnect']) {
            $this->disconnect();
        }

        parent::_after($test);
    }