Skip to content

Commit

Permalink
TE: moved PrestaShopBundle tests outside of Bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
mickaelandrieu committed Nov 22, 2017
1 parent fd446d8 commit 9599c85
Show file tree
Hide file tree
Showing 192 changed files with 3,656 additions and 669 deletions.
4 changes: 2 additions & 2 deletions .github/release/create_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ rm -f .gitignore
rm -f .gitmodules
rm -f .travis.yml

rm -rf app/cache; mkdir app/cache;
rm -rf app/logs; mkdir app/logs;
rm -rf var/cache; mkdir var/cache;
rm -rf var/logs; mkdir var/logs;

read -p "Do you want to delete the .git directory? " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ themes/default-bootstrap/modules/*/mails/*

# Symfony

/bin/
/.web-server-pid
/app/config/parameters.yml
/app/config/parameters.php
Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ sudo: required
dist: trusty

php:
- 5.4
- 5.6
- 7.0

Expand Down Expand Up @@ -49,10 +48,11 @@ script:
- bash travis-scripts/install-prestashop
- php app/console lint:twig src
- php app/console lint:twig app
- composer test
- composer test-admin
- composer phpunit-legacy
- composer phpunit-admin
- composer phpunit-sf
- composer phpunit-controllers
- bash travis-scripts/install-prestashop
- bash ./travis-scripts/run-selenium-tests
- bash ./travis-scripts/run-functional-tests # Must run before starter theme
- bash ./travis-scripts/test-startertheme
Expand Down
4 changes: 3 additions & 1 deletion admin-dev/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@

require_once(dirname(__FILE__).'/../config/config.inc.php');

$loader = require_once(dirname(__FILE__).'/../var/bootstrap.php.cache');
if (PHP_VERSION_ID < 70000) {
$loader = require_once(dirname(__FILE__).'/../var/bootstrap.php.cache');
}
11 changes: 9 additions & 2 deletions admin-dev/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@
}

// Prepare Symfony kernel to resolve route.
$loader = require_once __DIR__.'/../var/bootstrap.php.cache';
if (PHP_VERSION_ID < 70000) {
$loader = require_once __DIR__.'/../var/bootstrap.php.cache';
}
// Enable APC for autoloading to improve performance.
// You should change the ApcClassLoader first argument to a unique prefix
// in order to prevent cache key conflicts with other applications
Expand All @@ -77,12 +79,17 @@
require_once __DIR__.'/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';
$kernel = new AppKernel(_PS_MODE_DEV_?'dev':'prod', _PS_MODE_DEV_);
$kernel->loadClassCache();
if (PHP_VERSION_ID < 70000) {
$kernel->loadClassCache();
}
//$kernel = new AppCache($kernel);
// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
//Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
Request::setTrustedProxies([], Request::HEADER_X_FORWARDED_ALL);

try {
require_once __DIR__.'/../autoload.php';
$response = $kernel->handle($request, HttpKernelInterface::MASTER_REQUEST, false);
$response->send();
$kernel->terminate($request, $response);
Expand Down
4 changes: 1 addition & 3 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ framework:
engines: ['twig']
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
handler_id: ~
fragments: ~
http_method_override: true

Expand Down
2 changes: 1 addition & 1 deletion app/config/config_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ monolog:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: [!event]
channels: ["!event"]
console:
type: console
bubble: false
Expand Down
4 changes: 2 additions & 2 deletions app/config/config_prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ monolog:

doctrine:
orm:
metadata_cache_driver: %cache.driver%
query_cache_driver: %cache.driver%
metadata_cache_driver: "%cache.driver%"
query_cache_driver: "%cache.driver%"
4 changes: 2 additions & 2 deletions app/config/config_test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
parameters:
AdapterSecurityAdminClass: PrestaShopBundle\Tests\Mock\AdapterSecurityAdminMock
prestashop.security.voter.product.class: PrestaShopBundle\Tests\Mock\PageVoter
AdapterSecurityAdminClass: Tests\PrestaShopBundle\Mock\AdapterSecurityAdminMock
prestashop.security.voter.product.class: Tests\PrestaShopBundle\Mock\PageVoter

imports:
- { resource: config_dev.yml }
Expand Down
17 changes: 6 additions & 11 deletions ...estaShopBundle/Tests/DatabaseTestCase.php → autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,9 @@
* International Registered Trademark & Property of PrestaShop SA
*/

namespace PrestaShop\PrestaShop\Tests\TestCase;
use PHPUnit_Framework_TestCase;
use PrestaShopBundle\Tests\Utils\Database;

abstract class DatabaseTestCase extends PHPUnit_Framework_TestCase
{
public static function setUpBeforeClass()
{
Database::restoreTestDB();
}
}
/**
* Allow call of Legacy classes from classes in /src and /tests
* @see composer.json "files" property for custom autoloading
*/
require_once(__DIR__.'/config/defines.inc.php');
require_once(__DIR__.'/classes/PrestaShopAutoload.php');
28 changes: 28 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env php
<?php

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;

// if you don't want to setup permissions the proper way, just uncomment the following PHP line
// read https://symfony.com/doc/current/setup.html#checking-symfony-application-configuration-and-setup
// for more information
umask(0000);

set_time_limit(0);

require __DIR__.'/../vendor/autoload.php';
require_once __DIR__.'/../autoload.php';

$input = new ArgvInput();
$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev');
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(['--no-debug', '']) && $env !== 'prod';

if ($debug) {
Debug::enable();
}

$kernel = new AppKernel($env, $debug);
$application = new Application($kernel);
$application->run($input);
146 changes: 146 additions & 0 deletions bin/symfony_requirements
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/usr/bin/env php
<?php

require_once dirname(__FILE__).'/../var/SymfonyRequirements.php';

$lineSize = 70;
$symfonyRequirements = new SymfonyRequirements();
$iniPath = $symfonyRequirements->getPhpIniConfigPath();

echo_title('Symfony Requirements Checker');

echo '> PHP is using the following php.ini file:'.PHP_EOL;
if ($iniPath) {
echo_style('green', ' '.$iniPath);
} else {
echo_style('yellow', ' WARNING: No configuration file (php.ini) used by PHP!');
}

echo PHP_EOL.PHP_EOL;

echo '> Checking Symfony requirements:'.PHP_EOL.' ';

$messages = array();
foreach ($symfonyRequirements->getRequirements() as $req) {
if ($helpText = get_error_message($req, $lineSize)) {
echo_style('red', 'E');
$messages['error'][] = $helpText;
} else {
echo_style('green', '.');
}
}

$checkPassed = empty($messages['error']);

foreach ($symfonyRequirements->getRecommendations() as $req) {
if ($helpText = get_error_message($req, $lineSize)) {
echo_style('yellow', 'W');
$messages['warning'][] = $helpText;
} else {
echo_style('green', '.');
}
}

if ($checkPassed) {
echo_block('success', 'OK', 'Your system is ready to run Symfony projects');
} else {
echo_block('error', 'ERROR', 'Your system is not ready to run Symfony projects');

echo_title('Fix the following mandatory requirements', 'red');

foreach ($messages['error'] as $helpText) {
echo ' * '.$helpText.PHP_EOL;
}
}

if (!empty($messages['warning'])) {
echo_title('Optional recommendations to improve your setup', 'yellow');

foreach ($messages['warning'] as $helpText) {
echo ' * '.$helpText.PHP_EOL;
}
}

echo PHP_EOL;
echo_style('title', 'Note');
echo ' The command console could use a different php.ini file'.PHP_EOL;
echo_style('title', '~~~~');
echo ' than the one used with your web server. To be on the'.PHP_EOL;
echo ' safe side, please check the requirements from your web'.PHP_EOL;
echo ' server using the ';
echo_style('yellow', 'web/config.php');
echo ' script.'.PHP_EOL;
echo PHP_EOL;

exit($checkPassed ? 0 : 1);

function get_error_message(Requirement $requirement, $lineSize)
{
if ($requirement->isFulfilled()) {
return;
}

$errorMessage = wordwrap($requirement->getTestMessage(), $lineSize - 3, PHP_EOL.' ').PHP_EOL;
$errorMessage .= ' > '.wordwrap($requirement->getHelpText(), $lineSize - 5, PHP_EOL.' > ').PHP_EOL;

return $errorMessage;
}

function echo_title($title, $style = null)
{
$style = $style ?: 'title';

echo PHP_EOL;
echo_style($style, $title.PHP_EOL);
echo_style($style, str_repeat('~', strlen($title)).PHP_EOL);
echo PHP_EOL;
}

function echo_style($style, $message)
{
// ANSI color codes
$styles = array(
'reset' => "\033[0m",
'red' => "\033[31m",
'green' => "\033[32m",
'yellow' => "\033[33m",
'error' => "\033[37;41m",
'success' => "\033[37;42m",
'title' => "\033[34m",
);
$supports = has_color_support();

echo($supports ? $styles[$style] : '').$message.($supports ? $styles['reset'] : '');
}

function echo_block($style, $title, $message)
{
$message = ' '.trim($message).' ';
$width = strlen($message);

echo PHP_EOL.PHP_EOL;

echo_style($style, str_repeat(' ', $width));
echo PHP_EOL;
echo_style($style, str_pad(' ['.$title.']', $width, ' ', STR_PAD_RIGHT));
echo PHP_EOL;
echo_style($style, $message);
echo PHP_EOL;
echo_style($style, str_repeat(' ', $width));
echo PHP_EOL;
}

function has_color_support()
{
static $support;

if (null === $support) {
if (DIRECTORY_SEPARATOR == '\\') {
$support = false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI');
} else {
$support = function_exists('posix_isatty') && @posix_isatty(STDOUT);
}
}

return $support;
}
2 changes: 1 addition & 1 deletion cache/deprecated.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
*****************************

This folder has been deprecated since PrestaShop 1.7.
Make sure your code uses `app/cache/ENV` folder, please use the
Make sure your code uses `var/cache/ENV` folder, please use the
constant `_PS_CACHE_DIR_` which is available everywhere.
4 changes: 2 additions & 2 deletions classes/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public static function getDefaultTests()
{
$tests = array(
'upload' => false,
'cache_dir' => 'app/cache',
'log_dir' => 'app/logs',
'cache_dir' => 'var/cache',
'log_dir' => 'var/logs',
'img_dir' => 'img',
'module_dir' => 'modules',
'theme_lang_dir' => 'themes/'._THEME_NAME_.'/lang/',
Expand Down
9 changes: 5 additions & 4 deletions classes/PrestaShopAutoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static function getInstance()
*/
public static function getCacheFileIndex()
{
return _PS_ROOT_DIR_.DIRECTORY_SEPARATOR. 'app'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.(_PS_MODE_DEV_ ? 'dev' : 'prod').DIRECTORY_SEPARATOR.'class_index.php';
return _PS_ROOT_DIR_.DIRECTORY_SEPARATOR. 'var'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.(_PS_MODE_DEV_ ? 'dev' : 'prod').DIRECTORY_SEPARATOR.'class_index.php';
}

/**
Expand All @@ -98,7 +98,7 @@ public static function getCacheFileIndex()
*/
public static function getNamespacedStubFileIndex()
{
return _PS_ROOT_DIR_.DIRECTORY_SEPARATOR. 'app'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.(_PS_MODE_DEV_ ? 'dev' : 'prod').DIRECTORY_SEPARATOR.'namespaced_class_stub.php';
return _PS_ROOT_DIR_.DIRECTORY_SEPARATOR. 'var'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.(_PS_MODE_DEV_ ? 'dev' : 'prod').DIRECTORY_SEPARATOR.'namespaced_class_stub.php';
}

/**
Expand All @@ -108,7 +108,7 @@ public static function getNamespacedStubFileIndex()
*/
public static function getStubFileIndex()
{
return _PS_ROOT_DIR_.DIRECTORY_SEPARATOR. 'app'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.(_PS_MODE_DEV_ ? 'dev' : 'prod').DIRECTORY_SEPARATOR.'class_stub.php';
return _PS_ROOT_DIR_.DIRECTORY_SEPARATOR. 'var'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.(_PS_MODE_DEV_ ? 'dev' : 'prod').DIRECTORY_SEPARATOR.'class_stub.php';
}

/**
Expand Down Expand Up @@ -260,7 +260,8 @@ public function dumpFile($filename, $content)
/**
* Retrieve recursively all classes in a directory and its subdirectories
*
* @param string $path Relativ path from root to the directory
* @param string $path Relative path from root to the directory
* @param bool $hostMode Since 1.7, deprecated.
*
* @return array
*/
Expand Down
Loading

0 comments on commit 9599c85

Please sign in to comment.