-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ScaffoldTest, Travis and PHPUnit configuration
- Loading branch information
1 parent
37a08d1
commit db5a6d9
Showing
7 changed files
with
173 additions
and
16 deletions.
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 +1,4 @@ | ||
/vendor/ | ||
|
||
# For while unit testing | ||
/framework/ |
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,14 @@ | ||
language: php | ||
|
||
php: | ||
- 5.6 | ||
- 7.0 | ||
- 7.1 | ||
|
||
before_install: | ||
- travis_retry composer self-update | ||
- travis_retry composer require silverstripe/framework ^4.0@dev | ||
- travis_retry composer require phpunit/phpunit ^5.7 | ||
|
||
script: | ||
- php vendor/bin/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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,18 @@ | ||
<phpunit | ||
bootstrap="tests/bootstrap.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true"> | ||
<testsuites> | ||
<testsuite name="silverstripe-console"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist addUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./src</directory> | ||
<exclude /> | ||
</whitelist> | ||
</filter> | ||
</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,115 @@ | ||
<?php | ||
|
||
namespace SilverLeague\Console\Tests\Framework; | ||
|
||
use SilverLeague\Console\Command\SilverStripeCommand; | ||
use SilverLeague\Console\Framework\Loader\ConfigurationLoader; | ||
use SilverLeague\Console\Framework\Loader\SilverStripeLoader; | ||
use SilverLeague\Console\Framework\Bootstrap; | ||
use SilverLeague\Console\Framework\Scaffold; | ||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
/** | ||
* @coversDefaultClass \SilverLeague\Console\Framework\Scaffold | ||
* @package silverstripe-console | ||
* @author Robbie Averill <robbie@averill.co.nz> | ||
*/ | ||
class ScaffoldTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* The test subject | ||
* @var Scaffold | ||
*/ | ||
protected $scaffold; | ||
|
||
/** | ||
* Initiate the test subject | ||
*/ | ||
public function setUp() | ||
{ | ||
$this->scaffold = new Scaffold; | ||
} | ||
|
||
/** | ||
* Test that a Symfony Console Application is created, as well as the SilverStripe and Configuration Loaders | ||
* | ||
* @covers \SilverLeague\Console\Framework\ConsoleBase | ||
* @covers ::setSilverStripeLoader | ||
* @covers ::getSilverStripeLoader | ||
* @covers ::setConfigurationLoader | ||
* @covers ::getConfigurationLoader | ||
*/ | ||
public function testConstructor() | ||
{ | ||
$this->assertInstanceOf(Application::class, $this->scaffold->getApplication()); | ||
$this->assertInstanceOf(SilverStripeLoader::class, $this->scaffold->getSilverStripeLoader()); | ||
$this->assertInstanceOf(ConfigurationLoader::class, $this->scaffold->getConfigurationLoader()); | ||
} | ||
|
||
/** | ||
* Test that YAML configuration is loaded from the ConfigurationLoader in array format (YAML ~2.7 is | ||
* locked into the SilverStripe framework) | ||
* | ||
* @covers ::setConfiguration | ||
* @covers ::getConfiguration | ||
* @covers ::getConfigurationLoader | ||
* @covers \SilverLeague\Console\Framework\Loader\ConfigurationLoader | ||
*/ | ||
public function testLoadConfiguration() | ||
{ | ||
$config = $this->scaffold->getConfiguration(); | ||
|
||
$this->assertInternalType('array', $config); | ||
$this->assertArrayHasKey('Commands', $config); | ||
$this->assertContains("SilverLeague\Console\Command\Dev\BuildCommand", $config['Commands']); | ||
} | ||
|
||
/** | ||
* Test that the bootstrap method was called, initiating Bootstrap which defines this constant | ||
* | ||
* @covers ::bootstrap | ||
*/ | ||
public function testBootstrapWasCalled() | ||
{ | ||
$this->assertTrue(defined('SILVERSTRIPE_ROOT_DIR')); | ||
} | ||
|
||
/** | ||
* Test that the run method will run the Symfony Application | ||
* | ||
* @covers ::run | ||
*/ | ||
public function testRun() | ||
{ | ||
$mockApplication = $this->getMockBuilder(Application::class) | ||
->disableOriginalConstructor() | ||
->setMethods(['run']) | ||
->getMock(); | ||
|
||
$mockApplication | ||
->expects($this->once()) | ||
->method('run'); | ||
|
||
$this->scaffold->setApplication($mockApplication); | ||
$this->scaffold->run(); | ||
} | ||
|
||
/** | ||
* Test that scaffoldApplication sets the name and version of the SilverStripe Console application, adds | ||
* Commands and the "flush" InputOption | ||
* | ||
* @covers ::scaffoldApplication | ||
* @covers ::addCommands | ||
*/ | ||
public function testApplicationIsScaffolded() | ||
{ | ||
$this->assertSame(Scaffold::APPLICATION_NAME, $this->scaffold->getApplication()->getName()); | ||
$this->assertContains(Scaffold::APPLICATION_VERSION, $this->scaffold->getApplication()->getVersion()); | ||
$this->assertInstanceOf( | ||
InputOption::class, | ||
$this->scaffold->getApplication()->getDefinition()->getOption('flush') | ||
); | ||
$this->assertInstanceOf(SilverStripeCommand::class, $this->scaffold->getApplication()->find('dev:build')); | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
/** | ||
* Bootstrapping for the console unit tests | ||
* | ||
* @package silverstripe-console | ||
* @author Robbie Averill <robbie@averill.co.nz> | ||
*/ | ||
|
||
define('CONSOLE_BASE_DIR', realpath(__DIR__ . '/..')); | ||
require CONSOLE_BASE_DIR . '/vendor/autoload.php'; | ||
|
||
global $_FILE_TO_URL_MAPPING; | ||
$_FILE_TO_URL_MAPPING[CONSOLE_BASE_DIR] = 'http://localhost'; |