|
1 | | -<?php |
2 | | - |
3 | | -/** |
4 | | - * This file is part of CodeIgniter 4 framework. |
5 | | - * |
6 | | - * (c) CodeIgniter Foundation <admin@codeigniter.com> |
7 | | - * |
8 | | - * For the full copyright and license information, please view |
9 | | - * the LICENSE file that was distributed with this source code. |
10 | | - */ |
11 | | - |
12 | | -namespace CodeIgniter\Commands; |
13 | | - |
14 | | -use CodeIgniter\Test\CIUnitTestCase; |
15 | | -use CodeIgniter\Test\Filters\CITestStreamFilter; |
16 | | - |
17 | | -/** |
18 | | - * @internal |
19 | | - */ |
20 | | -final class SessionsCommandsTest extends CIUnitTestCase |
21 | | -{ |
22 | | - private $streamFilter; |
23 | | - |
24 | | - protected function setUp(): void |
25 | | - { |
26 | | - parent::setUp(); |
27 | | - |
28 | | - CITestStreamFilter::$buffer = ''; |
29 | | - |
30 | | - $this->streamFilter = stream_filter_append(STDOUT, 'CITestStreamFilter'); |
31 | | - $this->streamFilter = stream_filter_append(STDERR, 'CITestStreamFilter'); |
32 | | - } |
33 | | - |
34 | | - protected function tearDown(): void |
35 | | - { |
36 | | - stream_filter_remove($this->streamFilter); |
37 | | - |
38 | | - $result = str_replace(["\033[0;32m", "\033[0m", "\n"], '', CITestStreamFilter::$buffer); |
39 | | - $file = str_replace('APPPATH' . DIRECTORY_SEPARATOR, APPPATH, trim(substr($result, 14))); |
40 | | - if (file_exists($file)) { |
41 | | - unlink($file); |
42 | | - } |
43 | | - } |
44 | | - |
45 | | - public function testCreateMigrationCommand() |
46 | | - { |
47 | | - command('session:migration'); |
48 | | - |
49 | | - // make sure we end up with a migration class in the right place |
50 | | - // or at least that we claim to have done so |
51 | | - // separate assertions avoid console color codes |
52 | | - $this->assertStringContainsString('_CreateCiSessionsTable.php', CITestStreamFilter::$buffer); |
53 | | - } |
54 | | - |
55 | | - public function testOverriddenCreateMigrationCommand() |
56 | | - { |
57 | | - command('session:migration -t mygoodies'); |
58 | | - |
59 | | - // make sure we end up with a migration class in the right place |
60 | | - $this->assertStringContainsString('_CreateMygoodiesTable.php', CITestStreamFilter::$buffer); |
61 | | - } |
62 | | - |
63 | | - public function testCannotWriteFileOnCreateMigrationCommand() |
64 | | - { |
65 | | - if ('\\' === DIRECTORY_SEPARATOR) { |
66 | | - $this->markTestSkipped('chmod does not work as expected on Windows'); |
67 | | - } |
68 | | - |
69 | | - chmod(APPPATH . 'Database/Migrations', 0444); |
70 | | - |
71 | | - command('session:migration'); |
72 | | - $this->assertStringContainsString('Error while creating file:', CITestStreamFilter::$buffer); |
73 | | - |
74 | | - chmod(APPPATH . 'Database/Migrations', 0755); |
75 | | - } |
76 | | -} |
0 commit comments