Skip to content

$ php codecept.phar generate:test unit "./foo" causes <?php namespace .; #5818

@mipon

Description

@mipon

What are you trying to achieve?

Automate creating a test file using the generate:{suite/test} command, synched with IDE when a file is added/modified.

In this scenario, sometimes calculated relative path for the generating test file contains a dot. In that case, an invalid syntax is inserted in the resulting generated test file.

Passing a relative path is useful to keep a synchronized structure with the source directory. For example, passing "foo/bar" creates a test file unit/foo/barTest.php. This is great.

$ php codecept.phar generate:test unit "foo/bar"

However, when it contains a dot, like

$ php codecept.phar generate:test unit "./foo"

it creates a file fooTest.php with an invalid namespace syntax. The dot something passed by IDE.

What do you get instead?

A namespace with a dot gets inserted at the beginning of the generated file, which is invalid syntax and causes a fatal error. So it must be manually removed.

<?php namespace .;

class fooTest extends \Codeception\Test\Unit
{
    /**
     * @var \UnitTester
     */
    protected $tester;
    ...

Details

  • Codeception version: 4.0.1 (I downloaded it from the 4.0.2 link but it says 4.0.1)
  • PHP Version: 7.3
  • Operating System: Windows 10
  • Installation type: Phar
  • Suite configuration:
actor: UnitTester
modules:
    enabled:
        - Asserts
        - \Helper\Unit
    step_decorators: ~
error_level: "E_ALL ^ E_NOTICE"
bootstrap: _bootstrap.php

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions