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

[TASK] Move functional tests to PHPUnit #475

Merged
merged 1 commit into from
May 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
80 changes: 9 additions & 71 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ notifications:
- helmut@typo3.org

before_install:
- export COMPOSER_ROOT_VERSION=4.5.3
- |
export COMPOSER_ROOT_VERSION=4.5.3
export CONSOLE_ROOT="$PWD"
export TYPO3_PATH_ROOT="$CONSOLE_ROOT/.Build/Web"
export PATH="$PATH:./Scripts"
- if php -i | grep -q xdebug; then phpenv config-rm xdebug.ini; fi
- wget https://raw.github.com/lehmannro/assert.sh/v1.1/assert.sh && source assert.sh -v -x && rm assert.sh

Expand All @@ -52,85 +56,19 @@ before_script:
composer set-version $TRAVIS_TAG
# If this fails, we forgot to update version numbers before tagging the release
test -z "$(git diff --shortstat 2> /dev/null | tail -n1)";
typo3cms | grep $TRAVIS_TAG
fi
- composer extension-create-libs && ls -la Libraries/*.phar | grep -v ^-rwx
- git clean -dffx
- composer require typo3/cms="$TYPO3_VERSION"
- export TYPO3_PATH_ROOT="$PWD/.Build/Web"
- export PATH="$PATH:./Scripts"

script:
- >
echo;
echo "Running unit tests";
.Build/bin/phpunit -c .Build/vendor/nimut/testing-framework/res/Configuration/UnitTests.xml Tests/Unit/
- >
echo;
echo "Running php lint";
find . -name \*.php ! -path "./.Build/*" | parallel --gnu php -d display_errors=stderr -l {} > /dev/null \;

# Basic functional tests - all commands should exit with 0
find . -name \*.php ! -path "./.Build/*" | parallel --gnu php -d display_errors=stderr -l {} > /dev/null \;;
- >
if [ -n "$TRAVIS_TAG" ]; then
typo3cms | grep $TRAVIS_TAG
fi
- assert_raises "typo3cms foo" 1
- typo3cms help && [ ! -f "$TYPO3_PATH_ROOT/typo3conf/PackageStates.php" ]
- typo3cms install:setup --non-interactive --database-user-name="root" --database-host-name="localhost" --database-port="3306" --database-name="travis_test" --admin-user-name="admin" --admin-password="password" --site-name="Travis Install" --site-setup-type="createsite"
- echo 'select uid,title from pages limit 1' | typo3cms database:import | sed 's/[[:blank:]]//g' | grep 1Home
- chmod ugo-w $TYPO3_PATH_ROOT/typo3conf/LocalConfiguration.php && typo3cms extension:setupactive && chmod ug+w $TYPO3_PATH_ROOT/typo3conf/LocalConfiguration.php
- typo3cms help
- typo3cms help:autocomplete
- typo3cms help:autocomplete bash
- typo3cms help:autocomplete zsh
- typo3cms backend:lock
- typo3cms backend:lock
- typo3cms backend:unlock
- typo3cms backend:unlock
- typo3cms backend:lockforeditors
- typo3cms backend:lockforeditors
- typo3cms backend:unlockforeditors
- typo3cms backend:unlockforeditors
- typo3cms cache:flush
- typo3cms cache:flushgroups pages
- typo3cms cache:flushtags foo
- typo3cms cache:flushtags foo pages
- typo3cms cache:listgroups
- typo3cms cleanup:updatereferenceindex
- typo3cms database:updateschema "*" --verbose --dry-run
- typo3cms database:updateschema --verbose
- typo3cms database:updateschema "*" --verbose
- typo3cms database:export > travis_test.sql
- test $(typo3cms database:export --exclude-tables sys_log | grep "CREATE TABLE" | grep -c sys_log) -eq 0
- echo "SELECT username from be_users where admin=1;" | typo3cms database:import
- echo "DROP DATABASE travis_test;" | typo3cms database:import
- echo "CREATE DATABASE travis_test;" | mysql -uroot && cat travis_test.sql | typo3cms database:import
- typo3cms database:updateschema "*" --verbose
- typo3cms frontend:request / > /dev/null
- typo3cms documentation:generatexsd TYPO3\\CMS\\Fluid\\ViewHelpers > /dev/null
- typo3cms configuration:show BE/installToolPassword
- typo3cms configuration:showLocal BE/installToolPassword
- typo3cms configuration:showActive BE/installToolPassword
- typo3cms configuration:set BE/installToolPassword foobar && grep installToolPassword $TYPO3_PATH_ROOT/typo3conf/LocalConfiguration.php | grep foobar
- typo3cms configuration:remove BE/installToolPassword --force && grep -qv installToolPassword $TYPO3_PATH_ROOT/typo3conf/LocalConfiguration.php
- typo3cms configuration:set BE/installToolPassword blablupp && grep installToolPassword $TYPO3_PATH_ROOT/typo3conf/LocalConfiguration.php | grep blablupp
- typo3cms configuration:set EXTCONF/lang/availableLanguages/1 fr_FR && grep fr_FR $TYPO3_PATH_ROOT/typo3conf/LocalConfiguration.php
- typo3cms configuration:set EXTCONF/foo/bar baz && grep bar $TYPO3_PATH_ROOT/typo3conf/LocalConfiguration.php | grep baz
- rm -f $TYPO3_PATH_ROOT/typo3conf/PackageStates.php && typo3cms install:generatepackagestates --activate-default && [ -f "$TYPO3_PATH_ROOT/typo3conf/PackageStates.php" ]
- rm -f $TYPO3_PATH_ROOT/typo3conf/PackageStates.php && TYPO3_CONSOLE_FEATURE_GENERATE_PACKAGE_STATES=yes TYPO3_CONSOLE_TEST_SETUP=yes TYPO3_ACTIVATE_DEFAULT_FRAMEWORK_EXTENSIONS=yes composer dump-autoload -vv 2>&1 | grep 'generated PackageStates.php' && [ -f "$TYPO3_PATH_ROOT/typo3conf/PackageStates.php" ]
- grep sys_note "$TYPO3_PATH_ROOT/typo3conf/PackageStates.php"
- rm $TYPO3_PATH_ROOT/typo3temp/index.html && typo3cms install:fixfolderstructure && [ -f "$TYPO3_PATH_ROOT/typo3temp/index.html" ]
- typo3cms extension:list
- typo3cms extension:list --raw | grep extbase
- typo3cms extension:list --active --raw | grep extbase
- typo3cms extension:list --inactive --raw | tr '\n' ' ' | grep -v extbase
- cp -r Tests/Functional/Fixtures/ext_test .Build/Web/typo3conf/ext/
- typo3cms extension:activate ext_test && typo3cms cache:flush && typo3cms database:updateschema | grep 'No schema updates were performed'
- typo3cms extension:activate core && typo3cms database:updateschema | grep 'No schema updates were performed'
- typo3cms extension:setup core && typo3cms database:updateschema | grep 'No schema updates were performed'
- typo3cms extension:setupactive && typo3cms database:updateschema | grep 'No schema updates were performed'
- if typo3cms extension:list --raw | grep dbal; then typo3cms extension:activate adodb,dbal && typo3cms database:updateschema | grep 'No schema updates were performed'; fi
- typo3cms extension:removeinactive --force | grep 'The following directories have been removed'
echo "Running unit and functional tests…";
.Build/bin/phpunit;

after_script:
- >
Expand Down
26 changes: 12 additions & 14 deletions Classes/Command/BackendCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ class BackendCommandController extends CommandController
public function lockCommand($redirectUrl = null)
{
if (@is_file(PATH_typo3conf . 'LOCK_BACKEND')) {
$this->outputLine('<warning>Backend is already locked!</warning>');
$this->sendAndExit(0);
$this->outputLine('<warning>Backend is already locked.</warning>');
$this->quit(0);
}
\TYPO3\CMS\Core\Utility\GeneralUtility::writeFile(PATH_typo3conf . 'LOCK_BACKEND', (string)$redirectUrl);
if (!@is_file(PATH_typo3conf . 'LOCK_BACKEND')) {
$this->outputLine('<error>Could not create lock file \'typo3conf/LOCK_BACKEND\'!</error>');
$this->sendAndExit(2);
$this->outputLine('<error>Could not create lock file \'typo3conf/LOCK_BACKEND\'.</error>');
$this->quit(2);
} else {
$this->outputLine('<info>Backend has been locked. Access is denied for every user until it is unlocked again.</info>');
if ($redirectUrl !== null) {
Expand All @@ -55,13 +55,13 @@ public function lockCommand($redirectUrl = null)
public function unlockCommand()
{
if (!@is_file(PATH_typo3conf . 'LOCK_BACKEND')) {
$this->outputLine('<warning>Backend is already unlocked!</warning>');
$this->sendAndExit(0);
$this->outputLine('<warning>Backend is already unlocked.</warning>');
$this->quit(0);
}
unlink(PATH_typo3conf . 'LOCK_BACKEND');
if (@is_file(PATH_typo3conf . 'LOCK_BACKEND')) {
$this->outputLine('<error>Could not remove lock file \'typo3conf/LOCK_BACKEND\'!</error>');
$this->sendAndExit(2);
$this->outputLine('<error>Could not remove lock file \'typo3conf/LOCK_BACKEND\'.</error>');
$this->quit(2);
} else {
$this->outputLine('<info>Backend lock is removed. User can now access the backend again.</info>');
}
Expand Down Expand Up @@ -90,10 +90,9 @@ public function lockForEditorsCommand()
$lockedForEditors = $this->configurationService->getLocal('BE/adminOnly') !== self::LOCK_TYPE_UNLOCKED;
if (!$lockedForEditors) {
$this->configurationService->setLocal('BE/adminOnly', self::LOCK_TYPE_ADMIN);
$this->outputLine('<info>Locked backend for editor access!</info>');
$this->outputLine('<info>Locked backend for editor access.</info>');
} else {
$this->outputLine('<warning>The backend was already locked for editors, hence nothing was done.</warning>');
$this->sendAndExit(0);
}
}

Expand All @@ -110,10 +109,9 @@ public function unlockForEditorsCommand()
$lockedForEditors = $this->configurationService->getLocal('BE/adminOnly') !== self::LOCK_TYPE_UNLOCKED;
if ($lockedForEditors) {
$this->configurationService->setLocal('BE/adminOnly', self::LOCK_TYPE_UNLOCKED);
$this->outputLine('<info>Unlocked backend for editors!</info>');
$this->outputLine('<info>Unlocked backend for editors.</info>');
} else {
$this->outputLine('<warning>The backend was not locked for editors, hence nothing was done.</warning>');
$this->sendAndExit(0);
$this->outputLine('<warning>The backend was not locked for editors.</warning>');
}
}

Expand All @@ -124,7 +122,7 @@ protected function ensureConfigValueModifiable()
{
if (!$this->configurationService->localIsActive('BE/adminOnly')) {
$this->outputLine('<error>The configuration value BE/adminOnly is not modifiable. Is it forced to a value in Additional Configuration?</error>');
$this->sendAndExit(2);
$this->quit(2);
}
}
}
6 changes: 3 additions & 3 deletions Classes/Command/CacheCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function flushGroupsCommand(array $groups)
{
try {
$this->cacheService->flushGroups($groups);
$this->outputLine('Flushed all caches for group(s): "' . implode('","', $groups) . '"');
$this->outputLine('Flushed all caches for group(s): "' . implode('","', $groups) . '".');
} catch (NoSuchCacheGroupException $e) {
$this->outputLine($e->getMessage());
$this->sendAndExit(1);
Expand All @@ -113,9 +113,9 @@ public function flushTagsCommand(array $tags, array $groups = null)
try {
$this->cacheService->flushByTagsAndGroups($tags, $groups);
if ($groups === null) {
$this->outputLine('Flushed caches by tags "' . implode('","', $tags) . '"');
$this->outputLine('Flushed caches by tags "' . implode('","', $tags) . '".');
} else {
$this->outputLine('Flushed caches by tags "' . implode('","', $tags) . '" in groups: "' . implode('","', $groups) . '"');
$this->outputLine('Flushed caches by tags "' . implode('","', $tags) . '" in groups: "' . implode('","', $groups) . '".');
}
} catch (NoSuchCacheGroupException $e) {
$this->outputLine($e->getMessage());
Expand Down
2 changes: 1 addition & 1 deletion Classes/Command/ExtensionCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public function listCommand($active = false, $inactive = false, $raw = false)
} else {
$this->output->outputTable(
$extensionInformation,
['Package key', 'Version', 'Description']
['Extension key', 'Version', 'Description']
);
}
}
Expand Down
1 change: 1 addition & 0 deletions Classes/Install/CliSetupRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public function setup($interactiveSetup, array $givenRequestArguments)
}
// The TYPO3 installation process does not take care of setting up all extensions properly,
// so we do it manually here
$this->commandDispatcher->executeCommand('install:generatepackagestates', ['--activate-default' => true]);
$this->commandDispatcher->executeCommand('extension:setupactive');
}

Expand Down
25 changes: 23 additions & 2 deletions Classes/Mvc/Cli/CommandDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,25 @@ public static function createFromCommandRun(ProcessBuilder $processBuilder = nul
return self::create($typo3cmsCommandPath, $processBuilder, $phpFinder);
}

/**
* Useful for creating the object during the runtime of a test
*
* Just use the method without arguments for best results
*
* @param ProcessBuilder $processBuilder
* @param PhpExecutableFinder $phpFinder
* @throws \RuntimeException
* @return self
*/
public static function createFromTestRun(ProcessBuilder $processBuilder = null, PhpExecutableFinder $phpFinder = null)
{
if (!isset($_SERVER['argv'][0]) && strpos($_SERVER['argv'][0], 'phpunit') === false) {
throw new \RuntimeException('Tried to create typo3cms command runner from wrong context', 1493570522);
}
$typo3cmsCommandPath = dirname(dirname(dirname(__DIR__))) . '/Scripts/typo3cms';
return self::create($typo3cmsCommandPath, $processBuilder, $phpFinder);
}

/**
* Basic factory method, which need the exact path to the typo3cms binary to create the dispatcher
*
Expand Down Expand Up @@ -127,16 +146,18 @@ public static function create($typo3cmsCommandPath, ProcessBuilder $processBuild
* @param string $command Command identifier
* @param array $arguments Argument names will automatically be converted to dashed version, fi not provided like so
* @param array $environment Environment vars to be added to the command
* @param resource|string|\Traversable|null $input Inpupt (stdin) for the command
* @throws FailedSubProcessCommandException
* @return string Output of the executed command
* @return string
*/
public function executeCommand($command, array $arguments = [], array $environment = [])
public function executeCommand($command, array $arguments = [], array $environment = [], $input = null)
{
// We need to clone the builder to be able to re-use the object for multiple commands
$processBuilder = clone $this->processBuilder;

$processBuilder->add($command);
$processBuilder->addEnvironmentVariables($environment);
$processBuilder->setInput($input);

foreach ($arguments as $argumentName => $argumentValue) {
if (strpos($argumentName, '--') === 0) {
Expand Down
2 changes: 1 addition & 1 deletion Classes/Service/CacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected function ensureCacheGroupsExist($groups)
$sanitizedGroups = array_intersect($groups, $validGroups);
if (count($sanitizedGroups) !== count($groups)) {
$invalidGroups = array_diff($groups, $sanitizedGroups);
throw new NoSuchCacheGroupException('Invalid cache groups "' . implode(', ', $invalidGroups) . '"', 1399630162);
throw new NoSuchCacheGroupException('Invalid cache groups "' . implode(', ', $invalidGroups) . '".', 1399630162);
}
}

Expand Down