Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
641ccb3
Replace usage of APP and ROOT constants
AD7six Dec 28, 2014
e0969f4
Configure test APP and ROOT paths
AD7six Dec 28, 2014
cf5729d
Add the test app namespace to the dev autoloader
AD7six Dec 28, 2014
cfb7384
Update Namespace in test comparison files
AD7six Dec 28, 2014
7a73c85
Populate the test app files
AD7six Dec 28, 2014
98b892a
Use Configure::read calls, not constants
AD7six Dec 28, 2014
7d0278c
Undo some "beautified" php code in a test template
AD7six Dec 28, 2014
8a88d1a
More constant removals
AD7six Dec 28, 2014
80bd3b2
Don't derive the base namespace
AD7six Dec 28, 2014
501cbc3
Use the class loader for test namespaces
AD7six Dec 28, 2014
e766d4e
Use a plugin in this repo
AD7six Dec 28, 2014
3e93472
Add re-namespaced files from the core
AD7six Dec 28, 2014
2e4071b
Nothing calls this method
AD7six Dec 28, 2014
40a7057
Consistent file doc blocks
AD7six Dec 28, 2014
983c469
Reduce line length
AD7six Dec 28, 2014
b1df779
php-cs-fixer the test_app dir
AD7six Dec 28, 2014
e878400
phpcbf the test_app folder
AD7six Dec 28, 2014
43c5799
some further fixes
AD7six Dec 28, 2014
f8b1cfc
prefer dist
AD7six Dec 28, 2014
1a3a499
Remove extra newline
AD7six Dec 28, 2014
ede1566
Reenable disabled test
AD7six Dec 28, 2014
3c7dfe2
Explicit bootstrap file
AD7six Dec 28, 2014
eddf669
Re-instate usage of constants
AD7six Dec 28, 2014
0a19174
Undo irrelevant changes
AD7six Dec 28, 2014
790afb0
whoops
AD7six Dec 28, 2014
fec6c73
don't need to define that
AD7six Dec 28, 2014
fab9f10
don't need to use that
AD7six Dec 28, 2014
cfb7a11
don't need to ddefine that
AD7six Dec 28, 2014
2ca93df
Don't need that
AD7six Dec 28, 2014
107ccff
Don't need that either
AD7six Dec 28, 2014
fe1b79f
don't need to create dirs
AD7six Dec 28, 2014
f8bc120
Remove unused constants from the test bootstrap file
AD7six Dec 29, 2014
610a91b
whitespace
AD7six Dec 29, 2014
93d1bcd
Remove use of none-standard constant
AD7six Dec 29, 2014
2af0950
Remove the one use of CAKE
AD7six Dec 29, 2014
949d54a
Don't need to use cake's class loader
AD7six Dec 29, 2014
d94fec2
Correct version since for a test class
AD7six Dec 29, 2014
3821b70
remove unused classes from use list
AD7six Dec 29, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ matrix:

before_script:
- composer self-update
- composer install --no-interaction --dev
- composer install --no-interaction --prefer-dist
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi"
- sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi"
- sh -c "if [ '$RUN_COVERAGE' = '1' ]; then composer require --dev satooshi/php-coveralls:dev-master; fi"
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
},
"autoload-dev": {
"psr-4": {
"BakeTest\\": "tests/test_app/Plugin/BakeTest/src",
"Bake\\Test\\": "tests",
"Bake\\Test\\App\\": "tests/test_app/App",
"Cake\\Test\\": "./vendor/cakephp/cakephp/tests"
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Shell/BakeShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public function main()
public function loadTasks()
{
$tasks = [];
$tasks = $this->_findTasks($tasks, CAKE, 'Cake');

$tasks = $this->_findTasks($tasks, APP, Configure::read('App.namespace'));
foreach (Plugin::loaded() as $plugin) {
Expand Down
2 changes: 1 addition & 1 deletion src/Shell/Task/FixtureTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class FixtureTask extends BakeTask
public function getPath()
{
$dir = 'Fixture/';
$path = TESTS . $dir;
$path = ROOT . DS . 'tests' . DS . $dir;
if (isset($this->plugin)) {
$path = $this->_pluginPath($this->plugin) . 'tests/' . $dir;
}
Expand Down
13 changes: 10 additions & 3 deletions src/Shell/Task/TestTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function outputTypeChoices()
* Output a list of possible classnames you might want to generate a test for.
*
* @param string $type The typename to get classes for.
* @return void
* @return array
*/
public function outputClassChoices($type)
{
Expand All @@ -142,6 +142,8 @@ public function outputClassChoices($type)
}
$this->out('');
$this->out('Re-run your command as `cake bake ' . $type . ' <classname>`');

return $options;
}

/**
Expand Down Expand Up @@ -196,7 +198,12 @@ public function bake($type, $className)

$subject = $className;
list($namespace, $className) = namespaceSplit($fullClassName);
list($baseNamespace, $subNamespace) = explode('\\', $namespace, 2);

$baseNamespace = Configure::read('App.namespace');
if ($this->plugin) {
$baseNamespace = str_replace('/', '\\', $this->plugin);
}
$subNamespace = substr($namespace, strlen($baseNamespace) + 1);

$this->out("\n" . sprintf('Baking test case for %s ...', $fullClassName), 1, Shell::QUIET);

Expand Down Expand Up @@ -510,7 +517,7 @@ public function generateUses($type, $fullClassName)
public function getPath()
{
$dir = 'TestCase/';
$path = TESTS . $dir;
$path = ROOT . DS . 'tests' . DS . $dir;
if (isset($this->plugin)) {
$path = $this->_pluginPath($this->plugin) . 'tests/' . $dir;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Shell/BakeShellTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function setUp()
['in', 'out', 'hr', 'err', 'createFile', '_stop'],
[$this->io]
);
Configure::write('App.namespace', 'TestApp');
Configure::write('App.namespace', 'Bake\Test\App');
}

/**
Expand Down
18 changes: 9 additions & 9 deletions tests/TestCase/Shell/Task/FixtureTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function testInitializeCopyConnection()
*/
public function testGetPath()
{
$this->assertPathEquals(TESTS . 'Fixture/', $this->Task->getPath());
$this->assertPathEquals(ROOT . DS . 'tests' . DS . 'Fixture/', $this->Task->getPath());
}

/**
Expand Down Expand Up @@ -152,7 +152,7 @@ public function testMainWithTableOption()
{
$this->Task->connection = 'test';
$this->Task->params = ['table' => 'comments'];
$filename = $this->_normalizePath(TESTS . 'Fixture/ArticlesFixture.php');
$filename = $this->_normalizePath(ROOT . DS . 'tests' . DS . 'Fixture/ArticlesFixture.php');

$this->Task->expects($this->at(0))
->method('createFile')
Expand Down Expand Up @@ -192,12 +192,12 @@ public function testMainIntoAll()
->method('listAll')
->will($this->returnValue(['articles', 'comments']));

$filename = $this->_normalizePath(TESTS . 'Fixture/ArticlesFixture.php');
$filename = $this->_normalizePath(ROOT . DS . 'tests' . DS . 'Fixture/ArticlesFixture.php');
$this->Task->expects($this->at(0))
->method('createFile')
->with($filename, $this->stringContains('class ArticlesFixture'));

$filename = $this->_normalizePath(TESTS . 'Fixture/CommentsFixture.php');
$filename = $this->_normalizePath(ROOT . DS . 'tests' . DS . 'Fixture/CommentsFixture.php');
$this->Task->expects($this->at(1))
->method('createFile')
->with($filename, $this->stringContains('class CommentsFixture'));
Expand All @@ -218,12 +218,12 @@ public function testAllWithCountAndRecordsFlags()
$this->Task->Model->expects($this->any())->method('listAll')
->will($this->returnValue(['Articles', 'comments']));

$filename = $this->_normalizePath(TESTS . 'Fixture/ArticlesFixture.php');
$filename = $this->_normalizePath(ROOT . DS . 'tests' . DS . 'Fixture/ArticlesFixture.php');
$this->Task->expects($this->at(0))
->method('createFile')
->with($filename, $this->stringContains("'title' => 'Third Article'"));

$filename = $this->_normalizePath(TESTS . 'Fixture/CommentsFixture.php');
$filename = $this->_normalizePath(ROOT . DS . 'tests' . DS . 'Fixture/CommentsFixture.php');
$this->Task->expects($this->at(1))
->method('createFile')
->with($filename, $this->stringContains("'comment' => 'First Comment for First Article'"));
Expand All @@ -246,11 +246,11 @@ public function testAllWithSchemaImport()
$this->Task->Model->expects($this->any())->method('listAll')
->will($this->returnValue(['Articles', 'comments']));

$filename = $this->_normalizePath(TESTS . 'Fixture/ArticlesFixture.php');
$filename = $this->_normalizePath(ROOT . DS . 'tests' . DS . 'Fixture/ArticlesFixture.php');
$this->Task->expects($this->at(0))->method('createFile')
->with($filename, $this->stringContains("public \$import = ['model' => 'Articles'"));

$filename = $this->_normalizePath(TESTS . 'Fixture/CommentsFixture.php');
$filename = $this->_normalizePath(ROOT . DS . 'tests' . DS . 'Fixture/CommentsFixture.php');
$this->Task->expects($this->at(1))->method('createFile')
->with($filename, $this->stringContains("public \$import = ['model' => 'Comments'"));
$this->Task->expects($this->exactly(2))->method('createFile');
Expand Down Expand Up @@ -367,7 +367,7 @@ public function testRecordGenerationForBinaryAndFloat()
public function testGenerateFixtureFile()
{
$this->Task->connection = 'test';
$filename = $this->_normalizePath(TESTS . 'Fixture/ArticlesFixture.php');
$filename = $this->_normalizePath(ROOT . DS . 'tests' . DS . 'Fixture/ArticlesFixture.php');

$this->Task->expects($this->at(0))
->method('createFile')
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Shell/Task/ModelTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function testApplyAssociations()
*/
public function testApplyAssociationsConcreteClass()
{
Configure::write('App.namespace', 'TestApp');
Configure::write('App.namespace', 'Bake\Test\App');
$articles = TableRegistry::get('Articles');
$assocs = [
'belongsTo' => [
Expand Down
15 changes: 0 additions & 15 deletions tests/TestCase/Shell/Task/ProjectTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,4 @@ public function testExecuteWithAbsolutePath()
$contents = $File->read();
$this->assertRegExp('/define\(\'CAKE_CORE_INCLUDE_PATH\', .*?DS/', $contents);
}

/**
* Copy the TestApp route file so it can be modified.
*
* @return void
*/
protected function _cloneRoutes()
{
$File = new File(TEST_APP . 'TestApp/Config/routes.php');
$contents = $File->read();

mkdir(TMP . 'BakeTestApp/Config/', 0777, true);
$File = new File(TMP . 'BakeTestApp/Config/routes.php');
$File->write($contents);
}
}
2 changes: 1 addition & 1 deletion tests/TestCase/Shell/Task/SimpleBakeTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function testMainWithPlugin()
*/
public function testBake()
{
Configure::write('App.namespace', 'TestApp');
Configure::write('App.namespace', 'Bake\Test\App');

$this->Task->expects($this->once())
->method('createFile')
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Shell/Task/TemplateTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testGenerate()
{
$this->Task->expects($this->any())->method('in')->will($this->returnValue(1));

$result = $this->Task->generate('classes/test_object', ['test' => 'foo']);
$result = $this->Task->generate('example', ['test' => 'foo']);
$this->assertSameAsFile(__FUNCTION__ . '.ctp', $result);
}

Expand Down
62 changes: 23 additions & 39 deletions tests/TestCase/Shell/Task/TestTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

use Bake\Shell\Task\TemplateTask;
use Bake\Shell\Task\TestTask;
use Bake\Test\App\Controller\PostsController;
use Bake\Test\App\Model\Table\ArticlesTable;
use Bake\Test\App\Model\Table\CategoryThreadsTable;
use Bake\Test\TestCase\TestCase;
use Cake\Controller\Controller;
use Cake\Core\App;
Expand All @@ -25,9 +28,6 @@
use Cake\Network\Response;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use TestApp\Controller\PostsController;
use TestApp\Model\Table\ArticlesTable;
use TestApp\Model\Table\CategoryThreadsTable;

/**
* TestTaskTest class
Expand Down Expand Up @@ -162,23 +162,13 @@ public function testExecuteWithTwoArgs()
*/
public function testOutputClassOptionsForTable()
{
$this->io->expects($this->at(0))
->method('out')
->with($this->stringContains('You must provide'));
$this->io->expects($this->at(1))
->method('out')
->with($this->stringContains('1. ArticlesTable'));
$this->io->expects($this->at(2))
->method('out')
->with($this->stringContains('2. ArticlesTagsTable'));
$this->io->expects($this->at(3))
->method('out')
->with($this->stringContains('3. AuthUsersTable'));
$this->io->expects($this->at(4))
->method('out')
->with($this->stringContains('4. AuthorsTable'));
$expected = [
'ArticlesTable',
'CategoryThreadsTable'
];

$this->Task->outputClassChoices('Table');
$choices = $this->Task->outputClassChoices('Table');
$this->assertSame($expected, $choices);
}

/**
Expand All @@ -188,23 +178,17 @@ public function testOutputClassOptionsForTable()
*/
public function testOutputClassOptionsForTablePlugin()
{
Plugin::load('TestPlugin');
Plugin::load('BakeTest');
$this->Task->plugin = 'BakeTest';

$this->Task->plugin = 'TestPlugin';
$this->io->expects($this->at(0))
->method('out')
->with($this->stringContains('You must provide'));
$this->io->expects($this->at(1))
->method('out')
->with($this->stringContains('1. AuthorsTable'));
$this->io->expects($this->at(2))
->method('out')
->with($this->stringContains('2. CommentsTable'));
$this->io->expects($this->at(3))
->method('out')
->with($this->stringContains('3. TestPluginCommentsTable'));
$expected = [
'AuthorsTable',
'BakeTestCommentsTable',
'CommentsTable'
];

$this->Task->outputClassChoices('Table');
$choices = $this->Task->outputClassChoices('Table');
$this->assertSame($expected, $choices);
}

/**
Expand All @@ -215,7 +199,7 @@ public function testOutputClassOptionsForTablePlugin()
*/
public function testMethodIntrospection()
{
$result = $this->Task->getTestableMethods('TestApp\Model\Table\ArticlesTable');
$result = $this->Task->getTestableMethods('Bake\Test\App\Model\Table\ArticlesTable');
$expected = ['initialize', 'findpublished', 'dosomething', 'dosomethingelse'];
$this->assertEquals($expected, array_map('strtolower', $result));
}
Expand Down Expand Up @@ -375,7 +359,7 @@ public function testBakeModelTest()
*/
public function testBakeControllerTest()
{
Configure::write('App.namespace', 'TestApp');
Configure::write('App.namespace', 'Bake\Test\App');

$this->Task->expects($this->once())
->method('createFile')
Expand All @@ -392,7 +376,7 @@ public function testBakeControllerTest()
*/
public function testBakePrefixControllerTest()
{
Configure::write('App.namespace', 'TestApp');
Configure::write('App.namespace', 'Bake\Test\App');

$this->Task->expects($this->once())
->method('createFile')
Expand All @@ -410,7 +394,7 @@ public function testBakePrefixControllerTest()
*/
public function testBakeComponentTest()
{
Configure::write('App.namespace', 'TestApp');
Configure::write('App.namespace', 'Bake\Test\App');

$this->Task->expects($this->once())
->method('createFile')
Expand Down Expand Up @@ -600,7 +584,7 @@ public static function caseFileNameProvider()
public function testTestCaseFileName($type, $class, $expected)
{
$result = $this->Task->testCaseFileName($type, $class);
$this->assertPathEquals(TESTS . $expected, $result);
$this->assertPathEquals(ROOT . DS . 'tests' . DS . $expected, $result);
}

/**
Expand Down
Loading