Skip to content

Commit db5a6d9

Browse files
committedJan 3, 2017
Add ScaffoldTest, Travis and PHPUnit configuration
1 parent 37a08d1 commit db5a6d9

File tree

7 files changed

+173
-16
lines changed

7 files changed

+173
-16
lines changed
 

‎.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
/vendor/
2+
3+
# For while unit testing
4+
/framework/

‎.travis.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: php
2+
3+
php:
4+
- 5.6
5+
- 7.0
6+
- 7.1
7+
8+
before_install:
9+
- travis_retry composer self-update
10+
- travis_retry composer require silverstripe/framework ^4.0@dev
11+
- travis_retry composer require phpunit/phpunit ^5.7
12+
13+
script:
14+
- php vendor/bin/phpunit

‎composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"require": {
1313
"symfony/console": "^3.2",
14-
"symfony/yaml": "^3.2"
14+
"symfony/yaml": "~2.7"
1515
},
1616
"bin": [
1717
"bin/ssconsole"

‎composer.lock

+9-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎phpunit.xml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<phpunit
2+
bootstrap="tests/bootstrap.php"
3+
colors="true"
4+
convertErrorsToExceptions="true"
5+
convertNoticesToExceptions="true"
6+
convertWarningsToExceptions="true">
7+
<testsuites>
8+
<testsuite name="silverstripe-console">
9+
<directory>./tests</directory>
10+
</testsuite>
11+
</testsuites>
12+
<filter>
13+
<whitelist addUncoveredFilesFromWhitelist="true">
14+
<directory suffix=".php">./src</directory>
15+
<exclude />
16+
</whitelist>
17+
</filter>
18+
</phpunit>

‎tests/Framework/ScaffoldTest.php

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
namespace SilverLeague\Console\Tests\Framework;
4+
5+
use SilverLeague\Console\Command\SilverStripeCommand;
6+
use SilverLeague\Console\Framework\Loader\ConfigurationLoader;
7+
use SilverLeague\Console\Framework\Loader\SilverStripeLoader;
8+
use SilverLeague\Console\Framework\Bootstrap;
9+
use SilverLeague\Console\Framework\Scaffold;
10+
use Symfony\Component\Console\Application;
11+
use Symfony\Component\Console\Input\InputOption;
12+
13+
/**
14+
* @coversDefaultClass \SilverLeague\Console\Framework\Scaffold
15+
* @package silverstripe-console
16+
* @author Robbie Averill <robbie@averill.co.nz>
17+
*/
18+
class ScaffoldTest extends \PHPUnit_Framework_TestCase
19+
{
20+
/**
21+
* The test subject
22+
* @var Scaffold
23+
*/
24+
protected $scaffold;
25+
26+
/**
27+
* Initiate the test subject
28+
*/
29+
public function setUp()
30+
{
31+
$this->scaffold = new Scaffold;
32+
}
33+
34+
/**
35+
* Test that a Symfony Console Application is created, as well as the SilverStripe and Configuration Loaders
36+
*
37+
* @covers \SilverLeague\Console\Framework\ConsoleBase
38+
* @covers ::setSilverStripeLoader
39+
* @covers ::getSilverStripeLoader
40+
* @covers ::setConfigurationLoader
41+
* @covers ::getConfigurationLoader
42+
*/
43+
public function testConstructor()
44+
{
45+
$this->assertInstanceOf(Application::class, $this->scaffold->getApplication());
46+
$this->assertInstanceOf(SilverStripeLoader::class, $this->scaffold->getSilverStripeLoader());
47+
$this->assertInstanceOf(ConfigurationLoader::class, $this->scaffold->getConfigurationLoader());
48+
}
49+
50+
/**
51+
* Test that YAML configuration is loaded from the ConfigurationLoader in array format (YAML ~2.7 is
52+
* locked into the SilverStripe framework)
53+
*
54+
* @covers ::setConfiguration
55+
* @covers ::getConfiguration
56+
* @covers ::getConfigurationLoader
57+
* @covers \SilverLeague\Console\Framework\Loader\ConfigurationLoader
58+
*/
59+
public function testLoadConfiguration()
60+
{
61+
$config = $this->scaffold->getConfiguration();
62+
63+
$this->assertInternalType('array', $config);
64+
$this->assertArrayHasKey('Commands', $config);
65+
$this->assertContains("SilverLeague\Console\Command\Dev\BuildCommand", $config['Commands']);
66+
}
67+
68+
/**
69+
* Test that the bootstrap method was called, initiating Bootstrap which defines this constant
70+
*
71+
* @covers ::bootstrap
72+
*/
73+
public function testBootstrapWasCalled()
74+
{
75+
$this->assertTrue(defined('SILVERSTRIPE_ROOT_DIR'));
76+
}
77+
78+
/**
79+
* Test that the run method will run the Symfony Application
80+
*
81+
* @covers ::run
82+
*/
83+
public function testRun()
84+
{
85+
$mockApplication = $this->getMockBuilder(Application::class)
86+
->disableOriginalConstructor()
87+
->setMethods(['run'])
88+
->getMock();
89+
90+
$mockApplication
91+
->expects($this->once())
92+
->method('run');
93+
94+
$this->scaffold->setApplication($mockApplication);
95+
$this->scaffold->run();
96+
}
97+
98+
/**
99+
* Test that scaffoldApplication sets the name and version of the SilverStripe Console application, adds
100+
* Commands and the "flush" InputOption
101+
*
102+
* @covers ::scaffoldApplication
103+
* @covers ::addCommands
104+
*/
105+
public function testApplicationIsScaffolded()
106+
{
107+
$this->assertSame(Scaffold::APPLICATION_NAME, $this->scaffold->getApplication()->getName());
108+
$this->assertContains(Scaffold::APPLICATION_VERSION, $this->scaffold->getApplication()->getVersion());
109+
$this->assertInstanceOf(
110+
InputOption::class,
111+
$this->scaffold->getApplication()->getDefinition()->getOption('flush')
112+
);
113+
$this->assertInstanceOf(SilverStripeCommand::class, $this->scaffold->getApplication()->find('dev:build'));
114+
}
115+
}

‎tests/bootstrap.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/**
3+
* Bootstrapping for the console unit tests
4+
*
5+
* @package silverstripe-console
6+
* @author Robbie Averill <robbie@averill.co.nz>
7+
*/
8+
9+
define('CONSOLE_BASE_DIR', realpath(__DIR__ . '/..'));
10+
require CONSOLE_BASE_DIR . '/vendor/autoload.php';
11+
12+
global $_FILE_TO_URL_MAPPING;
13+
$_FILE_TO_URL_MAPPING[CONSOLE_BASE_DIR] = 'http://localhost';

0 commit comments

Comments
 (0)
Please sign in to comment.