Bake\Shell\Task\TestTask::testCaseFileName PHP Method

testCaseFileName() public method

Make the filename for the test case. resolve the suffixes for controllers and get the plugin path if needed.
public testCaseFileName ( string $type, string $className ) : string
$type string The Type of object you are generating tests for eg. controller
$className string The fully qualified classname of the class the test is being generated for.
return string filename the test should be created on.
    public function testCaseFileName($type, $className)
    {
        $path = $this->getPath();
        $namespace = Configure::read('App.namespace');
        if ($this->plugin) {
            $namespace = $this->plugin;
        }
        $classTail = substr($className, strlen($namespace) + 1);
        $path = $path . $classTail . 'Test.php';
        return str_replace(['/', '\\'], DS, $path);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Test filename generation for plugins.
  *
  * @return void
  */
 public function testTestCaseFileNamePlugin()
 {
     $this->Task->path = DS . 'my/path/tests/';
     Plugin::load('TestTest', ['path' => APP . 'Plugin' . DS . 'TestTest' . DS]);
     $this->Task->plugin = 'TestTest';
     $class = 'TestBake\\Model\\Entity\\Post';
     $result = $this->Task->testCaseFileName('entity', $class);
     $expected = APP . 'Plugin/TestTest/tests/TestCase/Model/Entity/PostTest.php';
     $this->assertPathEquals($expected, $result);
 }