Merge pull request #10405 from chinpei215/2.next-phpunit4.8

[2.next] Make test suites compatible with PHPUnit 4.8
This commit is contained in:
Mark Story 2017-03-25 10:31:54 -04:00 committed by GitHub
commit 68432f77de
12 changed files with 116 additions and 58 deletions

View file

@ -9,7 +9,10 @@ php:
- 7.1 - 7.1
env: env:
- DB=mysql matrix:
- DB=mysql
global:
- PHPUNIT=3.7.33
services: services:
- memcached - memcached
@ -17,6 +20,9 @@ services:
matrix: matrix:
fast_finish: true fast_finish: true
include: include:
- php: 5.3
env: DB=mysql PHPUNIT=4.8.35
- php: 5.4 - php: 5.4
env: DB=pgsql env: DB=pgsql
@ -28,8 +34,8 @@ matrix:
before_script: before_script:
- sh -c "composer global require 'phpunit/phpunit=3.7.33'" - composer global require "phpunit/phpunit=$PHPUNIT"
- sh -c "ln -s ~/.composer/vendor/phpunit/phpunit/PHPUnit ./vendors/PHPUnit" - echo "require_once '$HOME/.composer/vendor/autoload.php';" >> app/Config/bootstrap.php
- sudo locale-gen de_DE - sudo locale-gen de_DE
- sudo locale-gen es_ES - sudo locale-gen es_ES
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi" - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi"

View file

@ -159,7 +159,7 @@ class ConsoleInputArgument {
$option = $parent->addChild('argument'); $option = $parent->addChild('argument');
$option->addAttribute('name', $this->_name); $option->addAttribute('name', $this->_name);
$option->addAttribute('help', $this->_help); $option->addAttribute('help', $this->_help);
$option->addAttribute('required', $this->isRequired()); $option->addAttribute('required', (int)$this->isRequired());
$choices = $option->addChild('choices'); $choices = $option->addChild('choices');
foreach ($this->_choices as $valid) { foreach ($this->_choices as $valid) {
$choices->addChild('choice', $valid); $choices->addChild('choice', $valid);

View file

@ -205,10 +205,11 @@ class ConsoleInputOption {
$option->addAttribute('name', '--' . $this->_name); $option->addAttribute('name', '--' . $this->_name);
$short = ''; $short = '';
if (strlen($this->_short)) { if (strlen($this->_short)) {
$short = $this->_short; $short = '-' . $this->_short;
} }
$option->addAttribute('short', '-' . $short); $option->addAttribute('short', $short);
$option->addAttribute('boolean', $this->_boolean); $option->addAttribute('help', $this->_help);
$option->addAttribute('boolean', (int)$this->_boolean);
$option->addChild('default', $this->_default); $option->addChild('default', $this->_default);
$choices = $option->addChild('choices'); $choices = $option->addChild('choices');
foreach ($this->_choices as $valid) { foreach ($this->_choices as $valid) {

View file

@ -182,7 +182,6 @@ class HelpFormatter {
$xml->addChild('command', $parser->command()); $xml->addChild('command', $parser->command());
$xml->addChild('description', $parser->description()); $xml->addChild('description', $parser->description());
$xml->addChild('epilog', $parser->epilog());
$subcommands = $xml->addChild('subcommands'); $subcommands = $xml->addChild('subcommands');
foreach ($parser->subcommands() as $command) { foreach ($parser->subcommands() as $command) {
$command->xml($subcommands); $command->xml($subcommands);
@ -195,6 +194,7 @@ class HelpFormatter {
foreach ($parser->arguments() as $argument) { foreach ($parser->arguments() as $argument) {
$argument->xml($arguments); $argument->xml($arguments);
} }
$xml->addChild('epilog', $parser->epilog());
return $string ? $xml->asXml() : $xml; return $string ? $xml->asXml() : $xml;
} }

View file

@ -299,8 +299,8 @@ TEXT;
$expected = <<<TEXT $expected = <<<TEXT
<?xml version="1.0"?> <?xml version="1.0"?>
<shell> <shell>
<name>mycommand</name> <command>mycommand</command>
<description>Description text</description> <description />
<subcommands /> <subcommands />
<options> <options>
<option name="--help" short="-h" help="Display this help." boolean="1"> <option name="--help" short="-h" help="Display this help." boolean="1">
@ -322,11 +322,14 @@ TEXT;
<choice>aro</choice> <choice>aro</choice>
</choices> </choices>
</argument> </argument>
<argument help="Another argument." name="other_longer" required="0">
<choices/>
</argument>
</arguments> </arguments>
<epilog>epilog text</epilog> <epilog />
</shell> </shell>
TEXT; TEXT;
$this->assertEquals(new DomDocument($expected), new DomDocument($result), 'Help does not match'); $this->assertXmlStringEqualsXmlString($expected, $result, 'Help does not match');
} }
/** /**
@ -346,7 +349,7 @@ TEXT;
$expected = <<<TEXT $expected = <<<TEXT
<?xml version="1.0"?> <?xml version="1.0"?>
<shell> <shell>
<name>mycommand</name> <command>mycommand</command>
<description>Description text</description> <description>Description text</description>
<subcommands /> <subcommands />
<options> <options>
@ -367,7 +370,7 @@ TEXT;
<epilog>epilog text</epilog> <epilog>epilog text</epilog>
</shell> </shell>
TEXT; TEXT;
$this->assertEquals(new DomDocument($expected), new DomDocument($result), 'Help does not match'); $this->assertXmlStringEqualsXmlString($expected, $result, 'Help does not match');
} }
/** /**
@ -385,7 +388,7 @@ TEXT;
$expected = <<<TEXT $expected = <<<TEXT
<?xml version="1.0"?> <?xml version="1.0"?>
<shell> <shell>
<name>mycommand</name> <command>mycommand</command>
<description/> <description/>
<subcommands> <subcommands>
<command name="method" help="This is another command" /> <command name="method" help="This is another command" />
@ -404,7 +407,7 @@ TEXT;
<epilog/> <epilog/>
</shell> </shell>
TEXT; TEXT;
$this->assertEquals(new DomDocument($expected), new DomDocument($result), 'Help does not match'); $this->assertXmlStringEqualsXmlString($expected, $result, 'Help does not match');
} }
/** /**
@ -424,7 +427,7 @@ TEXT;
$expected = <<<TEXT $expected = <<<TEXT
<?xml version="1.0"?> <?xml version="1.0"?>
<shell> <shell>
<name>mycommand</name> <command>mycommand</command>
<description/> <description/>
<subcommands/> <subcommands/>
<options> <options>
@ -445,7 +448,7 @@ TEXT;
<epilog/> <epilog/>
</shell> </shell>
TEXT; TEXT;
$this->assertEquals(new DomDocument($expected), new DomDocument($result), 'Help does not match'); $this->assertXmlStringEqualsXmlString($expected, $result, 'Help does not match');
} }
/** /**
@ -464,7 +467,7 @@ TEXT;
$expected = <<<TEXT $expected = <<<TEXT
<?xml version="1.0"?> <?xml version="1.0"?>
<shell> <shell>
<name>mycommand</name> <command>mycommand</command>
<description/> <description/>
<subcommands/> <subcommands/>
<options> <options>
@ -488,7 +491,7 @@ TEXT;
<epilog/> <epilog/>
</shell> </shell>
TEXT; TEXT;
$this->assertEquals(new DomDocument($expected), new DomDocument($result), 'Help does not match'); $this->assertXmlStringEqualsXmlString($expected, $result, 'Help does not match');
} }
/** /**

View file

@ -198,7 +198,6 @@ class ThemeViewTest extends CakeTestCase {
/** /**
* testMissingView method * testMissingView method
* *
* @expectedException MissingViewException
* @return void * @return void
*/ */
public function testMissingView() { public function testMissingView() {
@ -211,17 +210,18 @@ class ThemeViewTest extends CakeTestCase {
$this->Controller->params['pass'] = array('home'); $this->Controller->params['pass'] = array('home');
$View = new TestTheme2View($this->Controller); $View = new TestTheme2View($this->Controller);
ob_start();
$View->getViewFileName('does_not_exist'); try {
$expected = ob_get_clean(); $View->getViewFileName('does_not_exist');
$this->assertRegExp("/PagesController::/", $expected); $this->fail('No exception');
$this->assertRegExp("/views(\/|\\\)themed(\/|\\\)my_theme(\/|\\\)pages(\/|\\\)does_not_exist.ctp/", $expected); } catch (MissingViewException $e) {
$this->assertContains('Pages' . DS . 'does_not_exist.ctp', $e->getMessage());
}
} }
/** /**
* testMissingLayout method * testMissingLayout method
* *
* @expectedException MissingLayoutException
* @return void * @return void
*/ */
public function testMissingLayout() { public function testMissingLayout() {
@ -232,11 +232,13 @@ class ThemeViewTest extends CakeTestCase {
$this->Controller->theme = 'my_theme'; $this->Controller->theme = 'my_theme';
$View = new TestTheme2View($this->Controller); $View = new TestTheme2View($this->Controller);
ob_start();
$View->getLayoutFileName(); try {
$expected = ob_get_clean(); $View->getLayoutFileName();
$this->assertRegExp("/Missing Layout/", $expected); $this->fail('No exception');
$this->assertRegExp("/views(\/|\\\)themed(\/|\\\)my_theme(\/|\\\)layouts(\/|\\\)whatever.ctp/", $expected); } catch (MissingLayoutException $e) {
$this->assertContains('Layouts' . DS . 'whatever.ctp', $e->getMessage());
}
} }
/** /**

View file

@ -625,9 +625,16 @@ class ViewTest extends CakeTestCase {
$this->Controller->params['pass'] = array('home'); $this->Controller->params['pass'] = array('home');
$View = new TestView($this->Controller); $View = new TestView($this->Controller);
ob_start();
$View->getViewFileName('does_not_exist'); $View->getViewFileName('does_not_exist');
}
/**
* Test for missing theme views
*
* @expectedException MissingViewException
* @return void
*/
public function testMissingThemeView() {
$this->ThemeController->plugin = null; $this->ThemeController->plugin = null;
$this->ThemeController->name = 'Pages'; $this->ThemeController->name = 'Pages';
$this->ThemeController->viewPath = 'Pages'; $this->ThemeController->viewPath = 'Pages';
@ -653,10 +660,16 @@ class ViewTest extends CakeTestCase {
$this->Controller->layout = 'whatever'; $this->Controller->layout = 'whatever';
$View = new TestView($this->Controller); $View = new TestView($this->Controller);
ob_start();
$View->getLayoutFileName(); $View->getLayoutFileName();
ob_get_clean(); }
/**
* Test for missing theme layouts
*
* @expectedException MissingLayoutException
* @return void
*/
public function testMissingThemeLayout() {
$this->ThemeController->plugin = null; $this->ThemeController->plugin = null;
$this->ThemeController->name = 'Posts'; $this->ThemeController->name = 'Posts';
$this->ThemeController->viewPath = 'posts'; $this->ThemeController->viewPath = 'posts';
@ -1512,7 +1525,6 @@ class ViewTest extends CakeTestCase {
public static function blockValueProvider() { public static function blockValueProvider() {
return array( return array(
'string' => array('A string value'), 'string' => array('A string value'),
'null' => array(null),
'decimal' => array(1.23456), 'decimal' => array(1.23456),
'object with __toString' => array(new TestObjectWithToString()), 'object with __toString' => array(new TestObjectWithToString()),
); );
@ -1631,26 +1643,33 @@ class ViewTest extends CakeTestCase {
/** /**
* Test that starting the same block twice throws an exception * Test that starting the same block twice throws an exception
* *
* @expectedException CakeException
* @return void * @return void
*/ */
public function testStartBlocksTwice() { public function testStartBlocksTwice() {
$this->View->start('first'); try {
echo 'In first '; $this->View->start('first');
$this->View->start('second'); $this->View->start('first');
echo 'In second'; $this->fail('No exception');
$this->View->start('first'); } catch (CakeException $e) {
ob_end_clean();
$this->assertTrue(true);
}
} }
/** /**
* Test that an exception gets thrown when you leave a block open at the end * Test that an exception gets thrown when you leave a block open at the end
* of a view. * of a view.
* *
* @expectedException CakeException
* @return void * @return void
*/ */
public function testExceptionOnOpenBlock() { public function testExceptionOnOpenBlock() {
$this->View->render('open_block'); try {
$this->View->render('open_block');
$this->fail('No exception');
} catch (CakeException $e) {
ob_end_clean();
$this->assertContains('The "no_close" block was left open', $e->getMessage());
}
} }
/** /**
@ -1673,23 +1692,33 @@ TEXT;
/** /**
* Make sure that extending the current view with itself causes an exception * Make sure that extending the current view with itself causes an exception
* *
* @expectedException LogicException
* @return void * @return void
*/ */
public function testExtendSelf() { public function testExtendSelf() {
$this->View->layout = false; try {
$this->View->render('extend_self'); $this->View->layout = false;
$this->View->render('extend_self');
$this->fail('No exception');
} catch (LogicException $e) {
ob_end_clean();
$this->assertContains('cannot have views extend themselves', $e->getMessage());
}
} }
/** /**
* Make sure that extending in a loop causes an exception * Make sure that extending in a loop causes an exception
* *
* @expectedException LogicException
* @return void * @return void
*/ */
public function testExtendLoop() { public function testExtendLoop() {
$this->View->layout = false; try {
$this->View->render('extend_loop'); $this->View->layout = false;
$this->View->render('extend_loop');
$this->fail('No exception');
} catch (LogicException $e) {
ob_end_clean();
$this->assertContains('cannot have views extend in a loop', $e->getMessage());
}
} }
/** /**
@ -1713,12 +1742,18 @@ TEXT;
/** /**
* Extending an element which doesn't exist should throw a missing view exception * Extending an element which doesn't exist should throw a missing view exception
* *
* @expectedException LogicException
* @return void * @return void
*/ */
public function testExtendMissingElement() { public function testExtendMissingElement() {
$this->View->layout = false; try {
$this->View->render('extend_missing_element'); $this->View->layout = false;
$this->View->render('extend_missing_element');
$this->fail('No exception');
} catch (LogicException $e) {
ob_end_clean();
ob_end_clean();
$this->assertContains('element', $e->getMessage());
}
} }
/** /**

View file

@ -76,6 +76,8 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
* @throws InvalidArgumentException * @throws InvalidArgumentException
*/ */
public function run(PHPUnit_Framework_TestResult $result = null) { public function run(PHPUnit_Framework_TestResult $result = null) {
$level = ob_get_level();
if (!empty($this->fixtureManager)) { if (!empty($this->fixtureManager)) {
$this->fixtureManager->load($this); $this->fixtureManager->load($this);
} }
@ -83,6 +85,11 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
if (!empty($this->fixtureManager)) { if (!empty($this->fixtureManager)) {
$this->fixtureManager->unload($this); $this->fixtureManager->unload($this);
} }
for ($i = ob_get_level(); $i < $level; ++$i) {
ob_start();
}
return $result; return $result;
} }

View file

@ -15,7 +15,7 @@
* @license http://www.opensource.org/licenses/mit-license.php MIT License * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/ */
if (!defined('__PHPUNIT_PHAR__')) { if (!class_exists('PHPUnit_TextUI_TestRunner')) {
require_once 'PHPUnit/TextUI/TestRunner.php'; require_once 'PHPUnit/TextUI/TestRunner.php';
} }
@ -52,7 +52,11 @@ class CakeTestRunner extends PHPUnit_TextUI_TestRunner {
} }
$fixture = $this->_getFixtureManager($arguments); $fixture = $this->_getFixtureManager($arguments);
foreach ($suite->getIterator() as $test) { $iterator = $suite->getIterator();
if ($iterator instanceof RecursiveIterator) {
$iterator = new RecursiveIteratorIterator($iterator);
}
foreach ($iterator as $test) {
if ($test instanceof CakeTestCase) { if ($test instanceof CakeTestCase) {
$fixture->fixturize($test); $fixture->fixturize($test);
$test->fixtureManager = $fixture; $test->fixtureManager = $fixture;

View file

@ -16,7 +16,7 @@
* @license http://www.opensource.org/licenses/mit-license.php MIT License * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/ */
if (!defined('__PHPUNIT_PHAR__')) { if (!class_exists('PHPUnit_TextUI_Command')) {
require_once 'PHPUnit/TextUI/Command.php'; require_once 'PHPUnit/TextUI/Command.php';
} }

View file

@ -15,7 +15,7 @@
* @license http://www.opensource.org/licenses/mit-license.php MIT License * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/ */
if (!defined('__PHPUNIT_PHAR__')) { if (!class_exists('PHPUnit_TextUI_ResultPrinter')) {
require_once 'PHPUnit/TextUI/ResultPrinter.php'; require_once 'PHPUnit/TextUI/ResultPrinter.php';
} }

View file

@ -27,7 +27,7 @@ $pluginDot = empty($plugin) ? null : $plugin . '.';
</p> </p>
<pre> <pre>
&lt;?php &lt;?php
class <?php echo h($class . ' extends ' . $plugin); ?>AppController { class <?php echo h($class . ' extends ' . (empty($plugin) ? '' : $plugin)); ?>AppController {
} }
</pre> </pre>