This repository has been archived by the owner on Jun 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Add the first integration test #62
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
composer.lock | ||
phpunit.xml | ||
/clover.xml | ||
/vendor | ||
/wordpress | ||
vendor | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
fixes: | ||
- "tests/vendor/wordplate/framework/src/::src/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
backupStaticAttributes="false" | ||
beStrictAboutTestsThatDoNotTestAnything="true" | ||
beStrictAboutOutputDuringTests="true" | ||
bootstrap="vendor/autoload.php" | ||
bootstrap="tests/vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
|
@@ -17,15 +17,19 @@ | |
> | ||
<testsuites> | ||
<testsuite name="WordPlate Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
<directory suffix="Test.php">.</directory> | ||
<exclude>tests/vendor</exclude> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./src</directory> | ||
<directory suffix=".php">tests/vendor/wordplate/framework/src</directory> | ||
</whitelist> | ||
</filter> | ||
<php> | ||
<env name="WP_ENV" value="testing"/> | ||
</php> | ||
<logging> | ||
<log type="coverage-clover" target="clover.xml"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to move this here? I would prefer if this was added to the |
||
</logging> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
clover.xml | ||
|
||
/vendor | ||
|
||
# This is a workaround due to inability to set up a repository of type "path" | ||
# targeting ../ directory in order to conduct integration tests with the package | ||
# in its current state (before pushing to external repository). | ||
# See https://github.com/composer/composer/issues/6085 | ||
/package | ||
|
||
# These paths are specified in composer.json and used by composer/installers. | ||
/public/wordpress | ||
/public/mu-plugins | ||
/public/plugins | ||
/public/themes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ | |
use WordPlate\Application; | ||
use WordPlate\Container; | ||
|
||
require_once __DIR__.'/stubs.php'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, maybe we can autoload this file instead of using require? |
||
|
||
/** | ||
* This is the container test class. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of WordPlate. | ||
* | ||
* (c) Vincent Klaiber <hello@vinkla.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WordPlate\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Process\Process; | ||
|
||
/** | ||
* This is the integration test class. It spins up WordPress using built-in | ||
* server. | ||
* | ||
* @author Mikhail Vasin <michaelvasin@gmail.com> | ||
*/ | ||
class IntegrationTest extends TestCase | ||
{ | ||
use RetryTrait; | ||
|
||
// Holds web server process, so it will be stopped when the testing is | ||
// over. | ||
private static $server; | ||
|
||
// TODO: iterate ports to find a free one, there is | ||
// no guarantee that a particular port will be available on a test | ||
// machine | ||
const HOST = 'localhost:12345'; | ||
const DOCROOT = __DIR__.'/public'; | ||
|
||
public static function setUpBeforeClass() | ||
{ | ||
self::$server = new Process( | ||
'php -S '.self::HOST.' -t '.self::DOCROOT | ||
); | ||
|
||
// Start web server in a separate process | ||
self::$server->start(); | ||
} | ||
|
||
/** | ||
* @retry 200 | ||
* @sleep 0.01 | ||
*/ | ||
public function testSmokeTest() | ||
{ | ||
// create curl resource | ||
$ch = curl_init(); | ||
|
||
// set url | ||
curl_setopt($ch, CURLOPT_URL, self::HOST); | ||
|
||
//return the transfer as a string | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
|
||
// $output contains the output string | ||
$output = curl_exec($ch); | ||
|
||
// Without a proper database connection it should currently look | ||
// something like this | ||
$this->assertRegExp( | ||
'/Error establishing a database connection/', $output | ||
); | ||
|
||
// close curl resource to free up system resources | ||
curl_close($ch); | ||
} | ||
|
||
public static function tearDownAfterClass() | ||
{ | ||
self::$server->stop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
namespace WordPlate\Tests; | ||
|
||
// Adapted from https://github.com/php-enqueue/enqueue-dev/blob/master/pkg/test/RetryTrait.php | ||
// (fixed typos, added sleep time) | ||
trait RetryTrait | ||
{ | ||
public function runBare(): void | ||
{ | ||
$e = null; | ||
$numberOfRetries = $this->getNumberOfRetries(); | ||
$sleepTime = $this->getSleepTime(); | ||
|
||
for ($i = 0; $i < $numberOfRetries; $i++) { | ||
try { | ||
parent::runBare(); | ||
|
||
return; | ||
} catch (\PHPUnit_Framework_IncompleteTestError $e) { | ||
throw $e; | ||
} catch (\PHPUnit_Framework_SkippedTestError $e) { | ||
throw $e; | ||
} catch (\Throwable $e) { | ||
// last one thrown below | ||
} catch (\Exception $e) { | ||
// last one thrown below | ||
} | ||
|
||
usleep($sleepTime * 1000000); | ||
} | ||
if ($e) { | ||
throw $e; | ||
} | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
private function getNumberOfRetries() | ||
{ | ||
$numberOfRetries = 1; | ||
|
||
if (isset($annotations['class']['retry'][0])) { | ||
$numberOfRetries = $annotations['class']['retry'][0]; | ||
} | ||
|
||
$annotations = $this->getAnnotations(); | ||
|
||
if (isset($annotations['method']['retry'][0])) { | ||
$numberOfRetries = $annotations['method']['retry'][0]; | ||
} | ||
|
||
if (false == is_numeric($numberOfRetries)) { | ||
throw new \LogicException( | ||
sprintf('The number of retries must be a number but got "%s"', | ||
var_export($numberOfRetries, true)) | ||
); | ||
} | ||
|
||
$numberOfRetries = (int) $numberOfRetries; | ||
|
||
if ($numberOfRetries <= 0) { | ||
throw new \LogicException( | ||
sprintf( | ||
'The number of retries must be > 0 but got "%s".', | ||
$numberOfRetries | ||
) | ||
); | ||
} | ||
|
||
return $numberOfRetries; | ||
} | ||
|
||
/** | ||
* @return float | ||
*/ | ||
private function getSleepTime() | ||
{ | ||
$sleepTime = 0; | ||
|
||
$annotations = $this->getAnnotations(); | ||
|
||
if (isset($annotations['class']['sleep'][0])) { | ||
$sleepTime = $annotations['class']['sleep'][0]; | ||
} | ||
|
||
if (isset($annotations['method']['sleep'][0])) { | ||
$sleepTime = $annotations['method']['sleep'][0]; | ||
} | ||
|
||
if (false == is_numeric($sleepTime)) { | ||
throw new \LogicException( | ||
sprintf('The sleep time must be a number but got "%s"', | ||
var_export($sleepTime, true) | ||
) | ||
); | ||
} | ||
|
||
$sleepTime = (float) $sleepTime; | ||
|
||
if ($sleepTime < 0) { | ||
throw new \LogicException( | ||
sprintf( | ||
'The sleep time must be a >= 0 but got "%s".', $sleepTime | ||
) | ||
); | ||
} | ||
|
||
return $sleepTime; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"description": "A WordPress site to test WordPlate with", | ||
"type": "project", | ||
"repositories": [ | ||
{ | ||
"type": "artifact", | ||
"url": "package" | ||
} | ||
], | ||
"require": { | ||
"wordplate/framework": "@dev" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^7.0", | ||
"symfony/process": "^4.0", | ||
"psy/psysh": "^0.8", | ||
"lib-curl": "*" | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"WordPlate\\Tests\\": "." | ||
} | ||
}, | ||
"config": { | ||
"preferred-install": "dist" | ||
}, | ||
"scripts": { | ||
"archive-package": "@composer archive --working-dir=../ --ignore-filters --dir=tests/package --file=wordplate-framework", | ||
"test": "vendor/bin/phpunit", | ||
"pre-install-cmd": "@archive-package", | ||
"pre-update-cmd": "@archive-package" | ||
}, | ||
"extra": { | ||
"wordpress-install-dir": "public/wordpress", | ||
"installer-paths": { | ||
"public/mu-plugins/{$name}": ["type:wordpress-muplugin"], | ||
"public/plugins/{$name}": ["type:wordpress-plugin"], | ||
"public/themes/{$name}": ["type:wordpress-theme"] | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this with PHPUnit in the
.travis.yml
file?