mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Updating Shell.test to use PHPUnit. There may still be some errors with the windows tests as I don't have access to windows at this time.
This commit is contained in:
parent
265609dfc1
commit
66699df9a0
1 changed files with 157 additions and 57 deletions
|
@ -34,9 +34,6 @@ if (!class_exists('ShellDispatcher')) {
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
Mock::generatePartial('ShellDispatcher', 'TestShellMockShellDispatcher', array(
|
|
||||||
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment'
|
|
||||||
));
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TestShell class
|
* TestShell class
|
||||||
|
@ -115,7 +112,12 @@ class ShellTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->Dispatcher =& new TestShellMockShellDispatcher();
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->Dispatcher = $this->getMock(
|
||||||
|
'ShellDispatcher',
|
||||||
|
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
||||||
|
);
|
||||||
$this->Shell =& new TestShell($this->Dispatcher);
|
$this->Shell =& new TestShell($this->Dispatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,6 +127,7 @@ class ShellTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function tearDown() {
|
public function tearDown() {
|
||||||
|
parent::tearDown();
|
||||||
ClassRegistry::flush();
|
ClassRegistry::flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +137,7 @@ class ShellTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testConstruct() {
|
public function testConstruct() {
|
||||||
$this->assertIsA($this->Shell->Dispatch, 'TestShellMockShellDispatcher');
|
$this->assertEquals($this->Dispatcher, $this->Shell->Dispatch);
|
||||||
$this->assertEqual($this->Shell->name, 'TestShell');
|
$this->assertEqual($this->Shell->name, 'TestShell');
|
||||||
$this->assertEqual($this->Shell->alias, 'TestShell');
|
$this->assertEqual($this->Shell->alias, 'TestShell');
|
||||||
}
|
}
|
||||||
|
@ -177,28 +180,43 @@ class ShellTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testIn() {
|
public function testIn() {
|
||||||
$this->Shell->Dispatch->setReturnValueAt(0, 'getInput', 'n');
|
$this->Dispatcher->expects($this->at(0))
|
||||||
$this->Shell->Dispatch->expectAt(0, 'getInput', array('Just a test?', array('y', 'n'), 'n'));
|
->method('getInput')
|
||||||
|
->with('Just a test?', array('y', 'n'), 'n')
|
||||||
|
->will($this->returnValue('n'));
|
||||||
|
|
||||||
|
$this->Dispatcher->expects($this->at(1))
|
||||||
|
->method('getInput')
|
||||||
|
->with('Just a test?', array('y', 'n'), 'n')
|
||||||
|
->will($this->returnValue('Y'));
|
||||||
|
|
||||||
|
$this->Dispatcher->expects($this->at(2))
|
||||||
|
->method('getInput')
|
||||||
|
->with('Just a test?', 'y,n', 'n')
|
||||||
|
->will($this->returnValue('y'));
|
||||||
|
|
||||||
|
$this->Dispatcher->expects($this->at(3))
|
||||||
|
->method('getInput')
|
||||||
|
->with('Just a test?', 'y/n', 'n')
|
||||||
|
->will($this->returnValue('y'));
|
||||||
|
|
||||||
|
$this->Dispatcher->expects($this->at(4))
|
||||||
|
->method('getInput')
|
||||||
|
->with('Just a test?', 'y', 'y')
|
||||||
|
->will($this->returnValue('y'));
|
||||||
|
|
||||||
$result = $this->Shell->in('Just a test?', array('y', 'n'), 'n');
|
$result = $this->Shell->in('Just a test?', array('y', 'n'), 'n');
|
||||||
$this->assertEqual($result, 'n');
|
$this->assertEqual($result, 'n');
|
||||||
|
|
||||||
$this->Shell->Dispatch->setReturnValueAt(1, 'getInput', 'Y');
|
|
||||||
$this->Shell->Dispatch->expectAt(1, 'getInput', array('Just a test?', array('y', 'n'), 'n'));
|
|
||||||
$result = $this->Shell->in('Just a test?', array('y', 'n'), 'n');
|
$result = $this->Shell->in('Just a test?', array('y', 'n'), 'n');
|
||||||
$this->assertEqual($result, 'Y');
|
$this->assertEqual($result, 'Y');
|
||||||
|
|
||||||
$this->Shell->Dispatch->setReturnValueAt(2, 'getInput', 'y');
|
|
||||||
$this->Shell->Dispatch->expectAt(2, 'getInput', array('Just a test?', 'y,n', 'n'));
|
|
||||||
$result = $this->Shell->in('Just a test?', 'y,n', 'n');
|
$result = $this->Shell->in('Just a test?', 'y,n', 'n');
|
||||||
$this->assertEqual($result, 'y');
|
$this->assertEqual($result, 'y');
|
||||||
|
|
||||||
$this->Shell->Dispatch->setReturnValueAt(3, 'getInput', 'y');
|
|
||||||
$this->Shell->Dispatch->expectAt(3, 'getInput', array('Just a test?', 'y/n', 'n'));
|
|
||||||
$result = $this->Shell->in('Just a test?', 'y/n', 'n');
|
$result = $this->Shell->in('Just a test?', 'y/n', 'n');
|
||||||
$this->assertEqual($result, 'y');
|
$this->assertEqual($result, 'y');
|
||||||
|
|
||||||
$this->Shell->Dispatch->setReturnValueAt(4, 'getInput', 'y');
|
|
||||||
$this->Shell->Dispatch->expectAt(4, 'getInput', array('Just a test?', 'y', 'y'));
|
|
||||||
$result = $this->Shell->in('Just a test?', 'y', 'y');
|
$result = $this->Shell->in('Just a test?', 'y', 'y');
|
||||||
$this->assertEqual($result, 'y');
|
$this->assertEqual($result, 'y');
|
||||||
|
|
||||||
|
@ -214,16 +232,28 @@ class ShellTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testOut() {
|
public function testOut() {
|
||||||
$this->Shell->Dispatch->expectAt(0, 'stdout', array("Just a test\n", false));
|
$this->Shell->Dispatch->expects($this->at(0))
|
||||||
|
->method('stdout')
|
||||||
|
->with("Just a test\n", false);
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(1))
|
||||||
|
->method('stdout')
|
||||||
|
->with("Just\na\ntest\n", false);
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(2))
|
||||||
|
->method('stdout')
|
||||||
|
->with("Just\na\ntest\n\n", false);
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(3))
|
||||||
|
->method('stdout')
|
||||||
|
->with("\n", false);
|
||||||
|
|
||||||
$this->Shell->out('Just a test');
|
$this->Shell->out('Just a test');
|
||||||
|
|
||||||
$this->Shell->Dispatch->expectAt(1, 'stdout', array("Just\na\ntest\n", false));
|
|
||||||
$this->Shell->out(array('Just', 'a', 'test'));
|
$this->Shell->out(array('Just', 'a', 'test'));
|
||||||
|
|
||||||
$this->Shell->Dispatch->expectAt(2, 'stdout', array("Just\na\ntest\n\n", false));
|
|
||||||
$this->Shell->out(array('Just', 'a', 'test'), 2);
|
$this->Shell->out(array('Just', 'a', 'test'), 2);
|
||||||
|
|
||||||
$this->Shell->Dispatch->expectAt(3, 'stdout', array("\n", false));
|
|
||||||
$this->Shell->out();
|
$this->Shell->out();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,16 +263,28 @@ class ShellTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testErr() {
|
public function testErr() {
|
||||||
$this->Shell->Dispatch->expectAt(0, 'stderr', array("Just a test\n"));
|
$this->Shell->Dispatch->expects($this->at(0))
|
||||||
|
->method('stderr')
|
||||||
|
->with("Just a test\n");
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(1))
|
||||||
|
->method('stderr')
|
||||||
|
->with("Just\na\ntest\n");
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(2))
|
||||||
|
->method('stderr')
|
||||||
|
->with("Just\na\ntest\n\n");
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(3))
|
||||||
|
->method('stderr')
|
||||||
|
->with("\n");
|
||||||
|
|
||||||
$this->Shell->err('Just a test');
|
$this->Shell->err('Just a test');
|
||||||
|
|
||||||
$this->Shell->Dispatch->expectAt(1, 'stderr', array("Just\na\ntest\n"));
|
|
||||||
$this->Shell->err(array('Just', 'a', 'test'));
|
$this->Shell->err(array('Just', 'a', 'test'));
|
||||||
|
|
||||||
$this->Shell->Dispatch->expectAt(2, 'stderr', array("Just\na\ntest\n\n"));
|
|
||||||
$this->Shell->err(array('Just', 'a', 'test'), 2);
|
$this->Shell->err(array('Just', 'a', 'test'), 2);
|
||||||
|
|
||||||
$this->Shell->Dispatch->expectAt(3, 'stderr', array("\n"));
|
|
||||||
$this->Shell->err();
|
$this->Shell->err();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,19 +309,22 @@ class ShellTest extends CakeTestCase {
|
||||||
public function testHr() {
|
public function testHr() {
|
||||||
$bar = '---------------------------------------------------------------';
|
$bar = '---------------------------------------------------------------';
|
||||||
|
|
||||||
$this->Shell->Dispatch->expectAt(0, 'stdout', array('', false));
|
$this->Shell->Dispatch->expects($this->at(0))->method('stdout')->with('', false);
|
||||||
$this->Shell->Dispatch->expectAt(1, 'stdout', array($bar . "\n", false));
|
$this->Shell->Dispatch->expects($this->at(1))->method('stdout')->with($bar . "\n", false);
|
||||||
$this->Shell->Dispatch->expectAt(2, 'stdout', array('', false));
|
$this->Shell->Dispatch->expects($this->at(2))->method('stdout')->with('', false);
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(3))->method('stdout')->with("\n", false);
|
||||||
|
$this->Shell->Dispatch->expects($this->at(4))->method('stdout')->with($bar . "\n", false);
|
||||||
|
$this->Shell->Dispatch->expects($this->at(5))->method('stdout')->with("\n", false);
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(6))->method('stdout')->with("\n\n", false);
|
||||||
|
$this->Shell->Dispatch->expects($this->at(7))->method('stdout')->with($bar . "\n", false);
|
||||||
|
$this->Shell->Dispatch->expects($this->at(8))->method('stdout')->with("\n\n", false);
|
||||||
|
|
||||||
$this->Shell->hr();
|
$this->Shell->hr();
|
||||||
|
|
||||||
$this->Shell->Dispatch->expectAt(3, 'stdout', array("\n", false));
|
|
||||||
$this->Shell->Dispatch->expectAt(4, 'stdout', array($bar . "\n", false));
|
|
||||||
$this->Shell->Dispatch->expectAt(5, 'stdout', array("\n", false));
|
|
||||||
$this->Shell->hr(true);
|
$this->Shell->hr(true);
|
||||||
|
|
||||||
$this->Shell->Dispatch->expectAt(3, 'stdout', array("\n\n", false));
|
|
||||||
$this->Shell->Dispatch->expectAt(4, 'stdout', array($bar . "\n", false));
|
|
||||||
$this->Shell->Dispatch->expectAt(5, 'stdout', array("\n\n", false));
|
|
||||||
$this->Shell->hr(2);
|
$this->Shell->hr(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,14 +334,23 @@ class ShellTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testError() {
|
public function testError() {
|
||||||
$this->Shell->Dispatch->expectAt(0, 'stderr', array("Error: Foo Not Found\n"));
|
$this->Shell->Dispatch->expects($this->at(0))
|
||||||
|
->method('stderr')
|
||||||
|
->with("Error: Foo Not Found\n");
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(1))
|
||||||
|
->method('stderr')
|
||||||
|
->with("Error: Foo Not Found\n");
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(2))
|
||||||
|
->method('stderr')
|
||||||
|
->with("Searched all...\n");
|
||||||
|
|
||||||
$this->Shell->error('Foo Not Found');
|
$this->Shell->error('Foo Not Found');
|
||||||
$this->assertIdentical($this->Shell->stopped, 1);
|
$this->assertIdentical($this->Shell->stopped, 1);
|
||||||
|
|
||||||
$this->Shell->stopped = null;
|
$this->Shell->stopped = null;
|
||||||
|
|
||||||
$this->Shell->Dispatch->expectAt(1, 'stderr', array("Error: Foo Not Found\n"));
|
|
||||||
$this->Shell->Dispatch->expectAt(2, 'stderr', array("Searched all...\n"));
|
|
||||||
$this->Shell->error('Foo Not Found', 'Searched all...');
|
$this->Shell->error('Foo Not Found', 'Searched all...');
|
||||||
$this->assertIdentical($this->Shell->stopped, 1);
|
$this->assertIdentical($this->Shell->stopped, 1);
|
||||||
}
|
}
|
||||||
|
@ -389,13 +443,13 @@ class ShellTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testCreateFile() {
|
public function testCreateFileNonInteractive() {
|
||||||
$this->skipIf(DIRECTORY_SEPARATOR === '\\', '%s Not supported on Windows');
|
$this->skipIf(DIRECTORY_SEPARATOR === '\\', '%s Not supported on Windows');
|
||||||
|
|
||||||
$path = TMP . 'shell_test';
|
$path = TMP . 'shell_test';
|
||||||
$file = $path . DS . 'file1.php';
|
$file = $path . DS . 'file1.php';
|
||||||
|
|
||||||
new Folder($path, true);
|
$Folder = new Folder($path, true);
|
||||||
|
|
||||||
$this->Shell->interactive = false;
|
$this->Shell->interactive = false;
|
||||||
|
|
||||||
|
@ -411,26 +465,54 @@ class ShellTest extends CakeTestCase {
|
||||||
$this->assertTrue(file_exists($file));
|
$this->assertTrue(file_exists($file));
|
||||||
$this->assertEqual(file_get_contents($file), $contents);
|
$this->assertEqual(file_get_contents($file), $contents);
|
||||||
|
|
||||||
|
$Folder->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test createFile when the shell is interactive.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testCreateFileInteractive() {
|
||||||
|
$this->skipIf(DIRECTORY_SEPARATOR === '\\', '%s Not supported on Windows');
|
||||||
|
|
||||||
|
$path = TMP . 'shell_test';
|
||||||
|
$file = $path . DS . 'file1.php';
|
||||||
|
$Folder = new Folder($path, true);
|
||||||
|
|
||||||
$this->Shell->interactive = true;
|
$this->Shell->interactive = true;
|
||||||
|
|
||||||
$this->Shell->Dispatch->setReturnValueAt(0, 'getInput', 'n');
|
$this->Shell->Dispatch->expects($this->at(5))
|
||||||
$this->Shell->Dispatch->expectAt(1, 'stdout', array('File exists, overwrite?', '*'));
|
->method('getInput')
|
||||||
|
->withAnyParameters()
|
||||||
|
->will($this->returnValue('n'));
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(9))
|
||||||
|
->method('getInput')
|
||||||
|
->withAnyParameters()
|
||||||
|
->will($this->returnValue('y'));
|
||||||
|
|
||||||
|
|
||||||
$contents = "<?php\necho 'yet another test';\n\$te = 'st';\n?>";
|
$contents = "<?php\necho 'yet another test';\n\$te = 'st';\n?>";
|
||||||
$result = $this->Shell->createFile($file, $contents);
|
|
||||||
$this->assertFalse($result);
|
|
||||||
$this->assertTrue(file_exists($file));
|
|
||||||
$this->assertNotEqual(file_get_contents($file), $contents);
|
|
||||||
|
|
||||||
$this->Shell->Dispatch->setReturnValueAt(1, 'getInput', 'y');
|
|
||||||
$this->Shell->Dispatch->expectAt(3, 'stdout', array('File exists, overwrite?', '*'));
|
|
||||||
|
|
||||||
$result = $this->Shell->createFile($file, $contents);
|
$result = $this->Shell->createFile($file, $contents);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertTrue(file_exists($file));
|
$this->assertTrue(file_exists($file));
|
||||||
$this->assertEqual(file_get_contents($file), $contents);
|
$this->assertEqual(file_get_contents($file), $contents);
|
||||||
|
|
||||||
$Folder = new Folder($path);
|
// no overwrite
|
||||||
|
$contents = 'new contents';
|
||||||
|
$result = $this->Shell->createFile($file, $contents);
|
||||||
|
$this->assertFalse($result);
|
||||||
|
$this->assertTrue(file_exists($file));
|
||||||
|
$this->assertNotEqual($contents, file_get_contents($file));
|
||||||
|
|
||||||
|
// overwrite
|
||||||
|
$contents = 'more new contents';
|
||||||
|
$result = $this->Shell->createFile($file, $contents);
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$this->assertTrue(file_exists($file));
|
||||||
|
$this->assertEquals($contents, file_get_contents($file));
|
||||||
|
|
||||||
$Folder->delete();
|
$Folder->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,13 +521,13 @@ class ShellTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testCreateFileWindows() {
|
public function testCreateFileWindowsNonInteractive() {
|
||||||
$this->skipUnless(DIRECTORY_SEPARATOR === '\\', 'testCreateFileWindows supported on Windows only');
|
$this->skipIf(DIRECTORY_SEPARATOR === '/', 'testCreateFileWindows supported on Windows only');
|
||||||
|
|
||||||
$path = TMP . 'shell_test';
|
$path = TMP . 'shell_test';
|
||||||
$file = $path . DS . 'file1.php';
|
$file = $path . DS . 'file1.php';
|
||||||
|
|
||||||
new Folder($path, true);
|
$Folder = new Folder($path, true);
|
||||||
|
|
||||||
$this->Shell->interactive = false;
|
$this->Shell->interactive = false;
|
||||||
|
|
||||||
|
@ -461,10 +543,32 @@ class ShellTest extends CakeTestCase {
|
||||||
$this->assertTrue(file_exists($file));
|
$this->assertTrue(file_exists($file));
|
||||||
$this->assertEqual(file_get_contents($file), $contents);
|
$this->assertEqual(file_get_contents($file), $contents);
|
||||||
|
|
||||||
|
$Folder = new Folder($path);
|
||||||
|
$Folder->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test createFile on windows with interactive on.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testCreateFileWindowsInteractive() {
|
||||||
|
$this->skipIf(DIRECTORY_SEPARATOR === '/', 'testCreateFileWindowsInteractive supported on Windows only');
|
||||||
|
|
||||||
|
$path = TMP . 'shell_test';
|
||||||
|
$file = $path . DS . 'file1.php';
|
||||||
|
|
||||||
|
$Folder = new Folder($path, true);
|
||||||
|
|
||||||
$this->Shell->interactive = true;
|
$this->Shell->interactive = true;
|
||||||
|
|
||||||
$this->Shell->Dispatch->setReturnValueAt(0, 'getInput', 'n');
|
$this->Shell->Dispatch->expects($this->at(5))
|
||||||
$this->Shell->Dispatch->expectAt(1, 'stdout', array('File exists, overwrite?'));
|
->method('getInput')
|
||||||
|
->will($this->returnValue('y'));
|
||||||
|
|
||||||
|
$this->Shell->Dispatch->expects($this->at(9))
|
||||||
|
->method('getInput')
|
||||||
|
->will($this->returnValue('n'));
|
||||||
|
|
||||||
$contents = "<?php\necho 'yet another test';\r\n\$te = 'st';\r\n?>";
|
$contents = "<?php\necho 'yet another test';\r\n\$te = 'st';\r\n?>";
|
||||||
$result = $this->Shell->createFile($file, $contents);
|
$result = $this->Shell->createFile($file, $contents);
|
||||||
|
@ -472,15 +576,11 @@ class ShellTest extends CakeTestCase {
|
||||||
$this->assertTrue(file_exists($file));
|
$this->assertTrue(file_exists($file));
|
||||||
$this->assertNotEqual(file_get_contents($file), $contents);
|
$this->assertNotEqual(file_get_contents($file), $contents);
|
||||||
|
|
||||||
$this->Shell->Dispatch->setReturnValueAt(1, 'getInput', 'y');
|
|
||||||
$this->Shell->Dispatch->expectAt(3, 'stdout', array('File exists, overwrite?'));
|
|
||||||
|
|
||||||
$result = $this->Shell->createFile($file, $contents);
|
$result = $this->Shell->createFile($file, $contents);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertTrue(file_exists($file));
|
$this->assertTrue(file_exists($file));
|
||||||
$this->assertEqual(file_get_contents($file), $contents);
|
$this->assertEqual(file_get_contents($file), $contents);
|
||||||
|
|
||||||
$Folder = new Folder($path);
|
|
||||||
$Folder->delete();
|
$Folder->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue