|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * This file is part of CodeIgniter 4 framework. |
| 7 | + * |
| 8 | + * (c) CodeIgniter Foundation <admin@codeigniter.com> |
| 9 | + * |
| 10 | + * For the full copyright and license information, please view |
| 11 | + * the LICENSE file that was distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace CodeIgniter\Commands\Generators; |
| 15 | + |
| 16 | +use CodeIgniter\Test\CIUnitTestCase; |
| 17 | +use CodeIgniter\Test\StreamFilterTrait; |
| 18 | +use PHPUnit\Framework\Attributes\Group; |
| 19 | + |
| 20 | +/** |
| 21 | + * @internal |
| 22 | + */ |
| 23 | +#[Group('Others')] |
| 24 | +final class FormRequestGeneratorTest extends CIUnitTestCase |
| 25 | +{ |
| 26 | + use StreamFilterTrait; |
| 27 | + |
| 28 | + protected function tearDown(): void |
| 29 | + { |
| 30 | + parent::tearDown(); |
| 31 | + |
| 32 | + $result = str_replace(["\033[0;32m", "\033[0m", "\n"], '', $this->getStreamFilterBuffer()); |
| 33 | + $file = str_replace('APPPATH' . DIRECTORY_SEPARATOR, APPPATH, trim(substr($result, 14))); |
| 34 | + $dir = dirname($file); |
| 35 | + |
| 36 | + if (is_file($file)) { |
| 37 | + unlink($file); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + public function testGenerateFormRequest(): void |
| 42 | + { |
| 43 | + command('make:request user'); |
| 44 | + |
| 45 | + $file = APPPATH . 'Requests/User.php'; |
| 46 | + |
| 47 | + $this->assertFileExists($file); |
| 48 | + $this->assertStringContainsString( |
| 49 | + 'Defaults to true in FormRequest. Override only when authorization', |
| 50 | + file_get_contents($file), |
| 51 | + ); |
| 52 | + } |
| 53 | + |
| 54 | + public function testGenerateFormRequestWithOptionSuffix(): void |
| 55 | + { |
| 56 | + command('make:request admin -suffix'); |
| 57 | + $this->assertFileExists(APPPATH . 'Requests/AdminRequest.php'); |
| 58 | + } |
| 59 | +} |
0 commit comments