codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.4k stars 1.9k forks source link

Bug: case-insensitive treatment of single-word view cells in Windows and macOS #7472

Closed paulbalandan closed 1 year ago

paulbalandan commented 1 year ago

PHP Version

8.2

CodeIgniter4 Version

develop

CodeIgniter4 Installation Method

Git

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

No response

What happened?

This test (CellGeneratorTest) currently fails on Windows:

    public function testGenerateCellSimpleName()
    {
        command('make:cell Another');

        // Check the class was generated
        $file = APPPATH . 'Cells/Another.php';
        $this->assertStringContainsString('File created: ' . clean_path($file), $this->getStreamFilterBuffer());
        $this->assertFileExists($file);
        $this->assertStringContainsString('class Another extends Cell', $this->getFileContents($file));

        // Check the view was generated
        $file = APPPATH . 'Cells/another.php';
        $this->assertStringContainsString('File created: ' . clean_path($file), $this->getStreamFilterBuffer());
        $this->assertFileExists($file);
        $this->assertSame("<div>\n    <!-- Your HTML here -->\n</div>\n", $this->getFileContents($file));
    }

This is because on Windows, Cells/Another.php is treated the same as Cells/another.php. Thus, only one file is generated, the class file. The view file is skipped.

Steps to Reproduce

Run the test above in Windows. Linux and MacOS are not affected.

Expected Output

I think we should add a check if the cell name is a single word and it is run through Windows. If that's the case, we forbid single word as cell name through a nice error message.

Anything else?

No response

kenjis commented 1 year ago

On the default file system on macOS also case-insensitive. So the test also fails. See https://github.com/codeigniter4/CodeIgniter4/pull/7471#issuecomment-1531329060

kenjis commented 1 year ago

I think we should add a check if the cell name is a single word and it is run through Windows. If that's the case, we forbid single word as cell name through a nice error message.

Do you mean to add the check in make:cell?

If so, I think just displaying an error message for single words is fine, regardless of platform.

To begin with, now we get an error on Windows/macOS because we can't create the HTML file. On Linux we can create the files without error, but if we move to a Windows/macOS server it won't work.