Move stepHasTag to trait (#169)

* Move stepHasTag to trait

* Fix tests
This commit is contained in:
Damian Mooyman 2017-08-02 11:48:53 +12:00 committed by Chris Joe
parent cf49da1926
commit 15c770b642
7 changed files with 44 additions and 37 deletions

View File

@ -1,7 +1,13 @@
language: php language: php
dist: precise
sudo: false sudo: false
cache:
directories:
- $HOME/.composer/cache/files
php: php:
- 5.6 - 5.6
@ -20,11 +26,12 @@ matrix:
env: PHPUNIT_TEST=1 env: PHPUNIT_TEST=1
before_script: before_script:
- export PATH=~/.composer/vendor/bin:$PATH
- composer validate - composer validate
- composer install --dev --prefer-dist - composer install --dev --prefer-dist
- composer require --prefer-dist --no-update symfony/config:^3.2 silverstripe/framework:4.0.x-dev silverstripe/siteconfig:4.0.x-dev silverstripe/config:1.0.x-dev silverstripe/admin:1.0.x-dev silverstripe/assets:1.0.x-dev silverstripe/versioned:1.0.x-dev --prefer-dist - composer require --prefer-dist --no-update silverstripe/recipe-core:1.0.x-dev
- composer update - composer update
- if [[ $PHPCS_TEST ]]; then pyrus install pear/PHP_CodeSniffer; fi - if [[ $PHPCS_TEST ]]; then composer global require squizlabs/php_codesniffer:^3 --prefer-dist --no-interaction --no-progress --no-suggest -o; fi
- phpenv rehash - phpenv rehash
script: script:

View File

@ -38,7 +38,7 @@
} }
}, },
"autoload-dev": { "autoload-dev": {
"psr-0": { "psr-4": {
"SilverStripe\\BehatExtension\\Tests\\": "tests/php/" "SilverStripe\\BehatExtension\\Tests\\": "tests/php/"
}, },
"classmap": [ "classmap": [

View File

@ -1,5 +1,5 @@
<phpunit bootstrap="tests/bootstrap.php" colors="true"> <phpunit colors="true">
<testsuite name="Default"> <testsuite name="Default">
<directory>tests</directory> <directory>tests/php</directory>
</testsuite> </testsuite>
</phpunit> </phpunit>

View File

@ -6,10 +6,8 @@ use Behat\Behat\Context\Context;
use Behat\Behat\Definition\Call; use Behat\Behat\Definition\Call;
use Behat\Behat\Hook\Scope\AfterScenarioScope; use Behat\Behat\Hook\Scope\AfterScenarioScope;
use Behat\Behat\Hook\Scope\AfterStepScope; use Behat\Behat\Hook\Scope\AfterStepScope;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Behat\Hook\Scope\BeforeStepScope; use Behat\Behat\Hook\Scope\BeforeStepScope;
use Behat\Behat\Hook\Scope\StepScope; use Behat\Behat\Hook\Scope\StepScope;
use Behat\Gherkin\Node\ScenarioNode;
use Behat\Mink\Driver\Selenium2Driver; use Behat\Mink\Driver\Selenium2Driver;
use Behat\Mink\Element\NodeElement; use Behat\Mink\Element\NodeElement;
use Behat\Mink\Session; use Behat\Mink\Session;
@ -1225,26 +1223,4 @@ JS;
{ {
file_put_contents('php://stderr', 'Exception caught: ' . $exception->getMessage()); file_put_contents('php://stderr', 'Exception caught: ' . $exception->getMessage());
} }
/**
* Check if a step has a given tag
*
* @param StepScope $event
* @param string $tag
* @return bool
*/
protected function stepHasTag(StepScope $event, $tag)
{
// Check feature
$feature = $event->getFeature();
if ($feature && $feature->hasTag($tag)) {
return true;
}
// Check scenario
$scenario = $this->getStepScenario($feature, $event->getStep());
if ($scenario && $scenario->hasTag($tag)) {
return true;
}
return false;
}
} }

View File

@ -2,6 +2,7 @@
namespace SilverStripe\BehatExtension\Utility; namespace SilverStripe\BehatExtension\Utility;
use Behat\Behat\Hook\Scope\StepScope;
use Behat\Gherkin\Node\FeatureNode; use Behat\Gherkin\Node\FeatureNode;
use Behat\Gherkin\Node\NodeInterface; use Behat\Gherkin\Node\NodeInterface;
use Behat\Gherkin\Node\ScenarioInterface; use Behat\Gherkin\Node\ScenarioInterface;
@ -60,4 +61,26 @@ trait StepHelper
} while (--$timeout >= 0); } while (--$timeout >= 0);
throw $firstEx; throw $firstEx;
} }
/**
* Check if a step has a given tag
*
* @param StepScope $event
* @param string $tag
* @return bool
*/
protected function stepHasTag(StepScope $event, $tag)
{
// Check feature
$feature = $event->getFeature();
if ($feature && $feature->hasTag($tag)) {
return true;
}
// Check scenario
$scenario = $this->getStepScenario($feature, $event->getStep());
if ($scenario && $scenario->hasTag($tag)) {
return true;
}
return false;
}
} }

View File

@ -1,7 +0,0 @@
<?php
$frameworkPath = __DIR__ . '/../framework';
$frameworkDir = basename($frameworkPath);
if (!defined('BASE_PATH')) {
define('BASE_PATH', dirname($frameworkPath));
}
require_once 'Core/Core.php';

View File

@ -9,12 +9,20 @@ use Behat\Mink\Mink;
use Behat\Mink\Driver\DriverInterface; use Behat\Mink\Driver\DriverInterface;
use Behat\Mink\Element\Element; use Behat\Mink\Element\Element;
use SilverStripe\BehatExtension\Tests\SilverStripeContextTest\FeatureContext; use SilverStripe\BehatExtension\Tests\SilverStripeContextTest\FeatureContext;
use SilverStripe\Dev\SapphireTest;
class SilverStripeContextTest extends \PHPUnit_Framework_TestCase class SilverStripeContextTest extends \PHPUnit_Framework_TestCase
{ {
protected $backupGlobals = false; protected $backupGlobals = false;
public static function setUpBeforeClass()
{
// Bootstrap test environment
parent::setUpBeforeClass();
SapphireTest::start();
}
/** /**
* @expectedException \LogicException * @expectedException \LogicException
* @expectedExceptionMessage Cannot find 'region_map' in the behat.yml * @expectedExceptionMessage Cannot find 'region_map' in the behat.yml