Skip to content

Commit 66c7735

Browse files
committed
Add tests.
1 parent 90dcabb commit 66c7735

File tree

5 files changed

+391
-0
lines changed

5 files changed

+391
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TestHelper\Test\TestCase\Command\Linter\Task;
6+
7+
use Cake\TestSuite\TestCase;
8+
use TestHelper\Command\Linter\Task\NoMixedInTemplatesTask;
9+
use TestHelper\Test\TestSuite\ConsoleOutput;
10+
11+
/**
12+
* @uses \TestHelper\Command\Linter\Task\NoMixedInTemplatesTask
13+
*/
14+
class NoMixedInTemplatesTaskTest extends TestCase {
15+
16+
protected ConsoleOutput $out;
17+
18+
protected ConsoleOutput $err;
19+
20+
protected NoMixedInTemplatesTask $task;
21+
22+
/**
23+
* setUp method
24+
*
25+
* @return void
26+
*/
27+
public function setUp(): void {
28+
parent::setUp();
29+
30+
$this->out = new ConsoleOutput();
31+
$this->err = new ConsoleOutput();
32+
$this->task = new NoMixedInTemplatesTask();
33+
}
34+
35+
/**
36+
* tearDown method
37+
*
38+
* @return void
39+
*/
40+
public function tearDown(): void {
41+
unset($this->task);
42+
parent::tearDown();
43+
}
44+
45+
/**
46+
* Test task name
47+
*
48+
* @return void
49+
*/
50+
public function testName(): void {
51+
$this->assertSame('no-mixed-in-templates', $this->task->name());
52+
}
53+
54+
/**
55+
* Test task description
56+
*
57+
* @return void
58+
*/
59+
public function testDescription(): void {
60+
$description = $this->task->description();
61+
$this->assertStringContainsString('mixed', $description);
62+
$this->assertStringContainsString('template', $description);
63+
}
64+
65+
/**
66+
* Test default paths
67+
*
68+
* @return void
69+
*/
70+
public function testDefaultPaths(): void {
71+
$paths = $this->task->defaultPaths();
72+
$this->assertContains('templates/', $paths);
73+
}
74+
75+
/**
76+
* Test does not support auto-fix
77+
*
78+
* @return void
79+
*/
80+
public function testSupportsAutoFix(): void {
81+
$this->assertFalse($this->task->supportsAutoFix());
82+
}
83+
84+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TestHelper\Test\TestCase\Command\Linter\Task;
6+
7+
use Cake\TestSuite\TestCase;
8+
use TestHelper\Command\Linter\Task\SingleRequestPerTestTask;
9+
use TestHelper\Test\TestSuite\ConsoleOutput;
10+
11+
/**
12+
* @uses \TestHelper\Command\Linter\Task\SingleRequestPerTestTask
13+
*/
14+
class SingleRequestPerTestTaskTest extends TestCase {
15+
16+
protected ConsoleOutput $out;
17+
18+
protected ConsoleOutput $err;
19+
20+
protected SingleRequestPerTestTask $task;
21+
22+
/**
23+
* setUp method
24+
*
25+
* @return void
26+
*/
27+
public function setUp(): void {
28+
parent::setUp();
29+
30+
$this->out = new ConsoleOutput();
31+
$this->err = new ConsoleOutput();
32+
$this->task = new SingleRequestPerTestTask();
33+
}
34+
35+
/**
36+
* tearDown method
37+
*
38+
* @return void
39+
*/
40+
public function tearDown(): void {
41+
unset($this->task);
42+
parent::tearDown();
43+
}
44+
45+
/**
46+
* Test task name
47+
*
48+
* @return void
49+
*/
50+
public function testName(): void {
51+
$this->assertSame('single-request-per-test', $this->task->name());
52+
}
53+
54+
/**
55+
* Test task description
56+
*
57+
* @return void
58+
*/
59+
public function testDescription(): void {
60+
$description = $this->task->description();
61+
$this->assertStringContainsString('get()', $description);
62+
$this->assertStringContainsString('post()', $description);
63+
}
64+
65+
/**
66+
* Test default paths
67+
*
68+
* @return void
69+
*/
70+
public function testDefaultPaths(): void {
71+
$paths = $this->task->defaultPaths();
72+
$this->assertContains('tests/TestCase/Controller/', $paths);
73+
}
74+
75+
/**
76+
* Test does not support auto-fix
77+
*
78+
* @return void
79+
*/
80+
public function testSupportsAutoFix(): void {
81+
$this->assertFalse($this->task->supportsAutoFix());
82+
}
83+
84+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TestHelper\Test\TestCase\Command\Linter\Task;
6+
7+
use Cake\TestSuite\TestCase;
8+
use TestHelper\Command\Linter\Task\UseBaseMigrationTask;
9+
use TestHelper\Test\TestSuite\ConsoleOutput;
10+
11+
/**
12+
* @uses \TestHelper\Command\Linter\Task\UseBaseMigrationTask
13+
*/
14+
class UseBaseMigrationTaskTest extends TestCase {
15+
16+
protected ConsoleOutput $out;
17+
18+
protected ConsoleOutput $err;
19+
20+
protected UseBaseMigrationTask $task;
21+
22+
/**
23+
* setUp method
24+
*
25+
* @return void
26+
*/
27+
public function setUp(): void {
28+
parent::setUp();
29+
30+
$this->out = new ConsoleOutput();
31+
$this->err = new ConsoleOutput();
32+
$this->task = new UseBaseMigrationTask();
33+
}
34+
35+
/**
36+
* tearDown method
37+
*
38+
* @return void
39+
*/
40+
public function tearDown(): void {
41+
unset($this->task);
42+
parent::tearDown();
43+
}
44+
45+
/**
46+
* Test task name
47+
*
48+
* @return void
49+
*/
50+
public function testName(): void {
51+
$this->assertSame('use-base-migration', $this->task->name());
52+
}
53+
54+
/**
55+
* Test task description
56+
*
57+
* @return void
58+
*/
59+
public function testDescription(): void {
60+
$description = $this->task->description();
61+
$this->assertStringContainsString('BaseMigration', $description);
62+
$this->assertStringContainsString('AbstractMigration', $description);
63+
}
64+
65+
/**
66+
* Test default paths
67+
*
68+
* @return void
69+
*/
70+
public function testDefaultPaths(): void {
71+
$paths = $this->task->defaultPaths();
72+
$this->assertContains('config/Migrations/', $paths);
73+
$this->assertContains('config/Seeds/', $paths);
74+
}
75+
76+
/**
77+
* Test does not support auto-fix
78+
*
79+
* @return void
80+
*/
81+
public function testSupportsAutoFix(): void {
82+
$this->assertFalse($this->task->supportsAutoFix());
83+
}
84+
85+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace TestHelper\Test\TestCase;
4+
5+
use Cake\TestSuite\TestCase;
6+
use TestHelper\TestHelperPlugin;
7+
8+
/**
9+
* @uses \TestHelper\TestHelperPlugin
10+
*/
11+
class TestHelperPluginTest extends TestCase {
12+
13+
/**
14+
* Test plugin name
15+
*
16+
* @return void
17+
*/
18+
public function testName() {
19+
$plugin = new TestHelperPlugin();
20+
$this->assertSame('TestHelper', $plugin->getName());
21+
}
22+
23+
/**
24+
* Test middleware is disabled
25+
*
26+
* @return void
27+
*/
28+
public function testMiddleware() {
29+
$plugin = new TestHelperPlugin();
30+
$middlewareQueue = $this->getMockBuilder('Cake\Http\MiddlewareQueue')
31+
->disableOriginalConstructor()
32+
->getMock();
33+
34+
$result = $plugin->middleware($middlewareQueue);
35+
$this->assertSame($middlewareQueue, $result);
36+
}
37+
38+
/**
39+
* Test bootstrap is disabled
40+
*
41+
* @return void
42+
*/
43+
public function testBootstrap() {
44+
$plugin = new TestHelperPlugin();
45+
$app = $this->getMockBuilder('Cake\Core\PluginApplicationInterface')->getMock();
46+
47+
// Bootstrap should do nothing since it's disabled
48+
$plugin->bootstrap($app);
49+
$this->assertTrue(true);
50+
}
51+
52+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
namespace TestHelper\Test\TestCase\Utility;
4+
5+
use Cake\TestSuite\TestCase;
6+
use TestHelper\Utility\ClassResolver;
7+
8+
class ClassResolverTest extends TestCase {
9+
10+
/**
11+
* Test type() method
12+
*
13+
* @return void
14+
*/
15+
public function testType() {
16+
$result = ClassResolver::type('Table');
17+
$this->assertSame('Model/Table', $result);
18+
19+
$result = ClassResolver::type('Entity');
20+
$this->assertSame('Model/Entity', $result);
21+
22+
$result = ClassResolver::type('Behavior');
23+
$this->assertSame('Model/Behavior', $result);
24+
25+
$result = ClassResolver::type('Task');
26+
$this->assertSame('Command/Task', $result);
27+
28+
$result = ClassResolver::type('Component');
29+
$this->assertSame('Controller/Component', $result);
30+
31+
$result = ClassResolver::type('Helper');
32+
$this->assertSame('View/Helper', $result);
33+
34+
$result = ClassResolver::type('CommandHelper');
35+
$this->assertSame('Command/Helper', $result);
36+
37+
$result = ClassResolver::type('Cell');
38+
$this->assertSame('View/Cell', $result);
39+
40+
$result = ClassResolver::type('Form');
41+
$this->assertSame('Form', $result);
42+
43+
$result = ClassResolver::type('Mailer');
44+
$this->assertSame('Mailer', $result);
45+
46+
// Unmapped type returns as-is
47+
$result = ClassResolver::type('Controller');
48+
$this->assertSame('Controller', $result);
49+
50+
$result = ClassResolver::type('Command');
51+
$this->assertSame('Command', $result);
52+
}
53+
54+
/**
55+
* Test suffix() method
56+
*
57+
* @return void
58+
*/
59+
public function testSuffix() {
60+
$result = ClassResolver::suffix('Entity');
61+
$this->assertSame('', $result);
62+
63+
$result = ClassResolver::suffix('CommandHelper');
64+
$this->assertSame('Helper', $result);
65+
66+
$result = ClassResolver::suffix('Cell');
67+
$this->assertSame('Cell', $result);
68+
69+
$result = ClassResolver::suffix('Form');
70+
$this->assertSame('Form', $result);
71+
72+
$result = ClassResolver::suffix('Mailer');
73+
$this->assertSame('Mailer', $result);
74+
75+
// Unmapped suffix returns type name
76+
$result = ClassResolver::suffix('Table');
77+
$this->assertSame('Table', $result);
78+
79+
$result = ClassResolver::suffix('Controller');
80+
$this->assertSame('Controller', $result);
81+
82+
$result = ClassResolver::suffix('Component');
83+
$this->assertSame('Component', $result);
84+
}
85+
86+
}

0 commit comments

Comments
 (0)