Skip to content

Commit

Permalink
Add ScaffoldTest, Travis and PHPUnit configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Jan 3, 2017
1 parent 37a08d1 commit db5a6d9
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/vendor/

# For while unit testing
/framework/
14 changes: 14 additions & 0 deletions .travis.yml
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"require": {
"symfony/console": "^3.2",
"symfony/yaml": "^3.2"
"symfony/yaml": "~2.7"
},
"bin": [
"bin/ssconsole"
Expand Down
24 changes: 9 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions phpunit.xml
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>
115 changes: 115 additions & 0 deletions tests/Framework/ScaffoldTest.php
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'));
}
}
13 changes: 13 additions & 0 deletions tests/bootstrap.php
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';

0 comments on commit db5a6d9

Please sign in to comment.