Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mise en place de tests fonctionnels avec Behat #149

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions .atoum.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,3 @@

$runner->disableCodeCoverage();
$runner->addTestsFromDirectory(__DIR__ . '/tests/units');

## Notifier (growlnotify)
$images = __DIR__ . '/vendor/atoum/atoum/resources/images/logo';

$report = $script->AddDefaultReport();

if(syslibExist('growlnotify') )
{
$notifier = new \mageekguy\atoum\report\fields\runner\result\notifier\image\growl();
$notifier
->setSuccessImage($images . DIRECTORY_SEPARATOR . 'success.png')
->setFailureImage($images . DIRECTORY_SEPARATOR . 'failure.png')
;
$report->addField($notifier, array(atoum\runner::runStop));
}

/**
* Return true if library is available on system
*
* @param string $libName
* @return boolean
*/
function syslibExist($libName)
{
return !is_null(shell_exec(sprintf('command -v %s 2>/dev/null', $libName)));
}
7 changes: 7 additions & 0 deletions .coke
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# coding standard
standard=PSR2

# Path to parse
src

# Path to ignore
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Application files
app/config.php
bin/*
behat.local.yml
behat.yml
deps.lock
vendor/
node_modules/
Expand All @@ -15,6 +17,8 @@ nbproject/
.settings/
# SublimeText
*.sublime-*
# PhpStorm
*.idea

# Backup files
*.*~
Expand Down
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ env:
php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7

before_script:
- wget -nc http://getcomposer.org/composer.phar
Expand All @@ -14,6 +17,6 @@ before_script:
- cp app/config_travis.php app/config.php
- php app/console db:install --test --load-fixtures

script: ./vendor/bin/atoum -d tests/units
script: ./bin/atoum

sudo: false
1 change: 0 additions & 1 deletion app/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@

// Add Twig extensions
$app['twig'] = $app->share($app->extend('twig', function($twig, $app) {
$twig->addExtension(new Twig_Extensions_Extension_Debug());
$twig->addExtension(new Twig_Extensions_Extension_Text());
$twig->addGlobal('ga_enabled', $app['ga.enabled']);
$twig->addGlobal('ga_ua', $app['ga.ua']);
Expand Down
3 changes: 3 additions & 0 deletions app/config_behat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

require_once __DIR__.'/config_test.php';
51 changes: 25 additions & 26 deletions app/console
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,43 @@

$app = require __DIR__ . '/app.php';

//Include the namespaces of the components we plan to use
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Aperophp\Database\Tool as DatabaseTool;

$goToTestEnv = function() use ($app) {
require __DIR__.'/config_test.php';
};

$importFile = function($file) use ($app) {
$app['db']->query(file_get_contents($file));
};
$changeEnvironment = function($env) use ($app) {
$env_config = __DIR__.'/config_'.$env.'.php';

$loadFixtures = function() use ($app, $importFile) {
$importFile(__DIR__.'/../data/sql/fixtures.sql');
if(file_exists($env_config)) {
require $env_config;
}
};

$console = new Application('Aperophp', '1');

$console->register('db:install')
->setDefinition(array(
new InputOption('test', '', InputOption::VALUE_NONE, 'Test mode'),
new InputOption('load-fixtures', '', InputOption::VALUE_NONE, 'Test mode'),
new InputOption('env', 'dev', InputOption::VALUE_OPTIONAL, 'Environment'),
new InputOption('load-fixtures', '', InputOption::VALUE_NONE, 'Import fixtures after database creation'),
))
->setDescription('Create database')
->setHelp('Usage: <info>php app/console db:install [--test] [--load-fixtures]</info>')
->setHelp('Usage: <info>php app/console db:install [--env=dev] [--load-fixtures]</info>')
->setCode(
function(InputInterface $input, OutputInterface $output) use ($app, $goToTestEnv, $importFile, $loadFixtures) {
if ($input->getOption('test')) {
$goToTestEnv();
}
function(InputInterface $input, OutputInterface $output) use ($app, $changeEnvironment) {
$output->writeln('<comment>Env : '.$input->getOption('env').'</comment>');
$changeEnvironment($input->getOption('env'));

$databaseTool = new DatabaseTool($app['db']);

$output->writeln('<info>Create schema.</info>');
$importFile(__DIR__ . '/../data/sql/schema.mysql.sql');
$databaseTool->createSchema(__DIR__ . '/../data/sql/schema.mysql.sql');

if ($input->getOption('load-fixtures')) {
$output->writeln('<info>Load fixtures.</info>');
$loadFixtures();
$databaseTool->loadFixtures(__DIR__.'/../data/sql/fixtures.sql');
}

$output->writeln('<info>Installation done.</info>');
Expand All @@ -51,17 +48,19 @@ $console->register('db:install')

$console->register('db:load-fixtures')
->setDefinition(array(
new InputOption('test', '', InputOption::VALUE_NONE, 'Test mode'),
new InputOption('env', '', InputOption::VALUE_NONE, 'Environment'),
))
->setDescription('Create database')
->setHelp('Usage: <info>php app/console db:load-fixtures [--test]</info>')
->setHelp('Usage: <info>php app/console db:load-fixtures [--env=dev]</info>')
->setCode(
function(InputInterface $input, OutputInterface $output) use ($app, $goToTestEnv, $loadFixtures) {
if ($input->getOption('test')) {
$goToTestEnv();
}
function(InputInterface $input, OutputInterface $output) use ($app, $changeEnvironment) {
$output->writeln('<comment>Env : '.$input->getOption('env').'</comment>');
$changeEnvironment($input->getOption('env'));

$databaseTool = new DatabaseTool($app['db']);

$loadFixtures();
$output->writeln('<info>Load fixtures</info>');
$databaseTool->loadFixtures(__DIR__.'/../data/sql/fixtures.sql');
}
);

Expand Down
7 changes: 7 additions & 0 deletions behat.local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
default:
context:
parameters:
base_url: http://www.aperophp.dev
extensions:
Behat\MinkExtension\Extension:
base_url: http://www.aperophp.dev
4 changes: 2 additions & 2 deletions bin/tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh

php app/console db:install --test --load-fixtures
php app/console db:install --env=test --load-fixtures

./vendor/bin/atoum
./bin/atoum
15 changes: 10 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"minimum-stability" : "dev",
"require": {
"silex/silex" : "1.0.*",
"doctrine/common" : "2.4.*",
"doctrine/dbal" : "2.4.*",
"twig/twig" : "1.12.*",
"twig/extensions" : "dev-master",
"doctrine/common" : "~2.4",
"doctrine/dbal" : "~2.4",
"twig/twig" : "~1.12",
"twig/extensions" : "~1.3",
"symfony/class-loader" : "2.1.x",
"symfony/form" : "2.1.x",
"symfony/validator" : "2.1.x",
Expand All @@ -27,7 +27,12 @@
"tijsverkoyen/akismet" : "1.1.0"
},
"require-dev": {
"atoum/atoum" : "dev-master"
"atoum/atoum" : "~2.2",
"behat/behat" : "~2.4",
"behat/mink-extension" : "~1.0",
"behat/mink-goutte-driver" : "~1.0",
"sensiolabs/behat-page-object-extension" : "~1.0",
"bossa/phpspec2-expect" : "dev-master"
},
"autoload": {
"psr-0": {
Expand Down
Loading