Bake\Shell\Task\TestTask::bake PHP Метод

bake() публичный Метод

Completes final steps for generating data to create test case.
public bake ( string $type, string $className ) : string | boolean
$type string Type of object to bake test case for ie. Model, Controller
$className string the 'cake name' for the class ie. Posts for the PostsController
Результат string | boolean
    public function bake($type, $className)
    {
        if (!isset($this->classSuffixes[strtolower($type)]) || !isset($this->classTypes[ucfirst($type)])) {
            return false;
        }
        $fullClassName = $this->getRealClassName($type, $className);
        if (empty($this->params['no-fixture'])) {
            if (!empty($this->params['fixtures'])) {
                $fixtures = array_map('trim', explode(',', $this->params['fixtures']));
                $this->_fixtures = array_filter($fixtures);
            } elseif ($this->typeCanDetectFixtures($type) && class_exists($fullClassName)) {
                $this->out('Bake is detecting possible fixtures...');
                $testSubject = $this->buildTestSubject($type, $fullClassName);
                $this->generateFixtureList($testSubject);
            }
        }
        $methods = [];
        if (class_exists($fullClassName)) {
            $methods = $this->getTestableMethods($fullClassName);
        }
        $mock = $this->hasMockClass($type, $fullClassName);
        list($preConstruct, $construction, $postConstruct) = $this->generateConstructor($type, $fullClassName);
        $uses = $this->generateUses($type, $fullClassName);
        $subject = $className;
        list($namespace, $className) = namespaceSplit($fullClassName);
        $baseNamespace = Configure::read('App.namespace');
        if ($this->plugin) {
            $baseNamespace = $this->_pluginNamespace($this->plugin);
        }
        $subNamespace = substr($namespace, strlen($baseNamespace) + 1);
        $properties = $this->generateProperties($type, $subject, $fullClassName);
        $this->out("\n" . sprintf('Baking test case for %s ...', $fullClassName), 1, Shell::QUIET);
        $this->BakeTemplate->set('fixtures', $this->_fixtures);
        $this->BakeTemplate->set('plugin', $this->plugin);
        $this->BakeTemplate->set(compact('subject', 'className', 'properties', 'methods', 'type', 'fullClassName', 'mock', 'type', 'preConstruct', 'postConstruct', 'construction', 'uses', 'baseNamespace', 'subNamespace', 'namespace'));
        $out = $this->BakeTemplate->generate('tests/test_case');
        $filename = $this->testCaseFileName($type, $fullClassName);
        $emptyFile = $this->getPath() . $this->getSubspacePath($type) . DS . 'empty';
        $this->_deleteEmptyFile($emptyFile);
        if ($this->createFile($filename, $out)) {
            return $out;
        }
        return false;
    }

Usage Example

Пример #1
0
 /**
  * Test baking within a plugin.
  *
  * @return void
  */
 public function testBakePlugin()
 {
     $this->_loadTestPlugin('TestBake');
     $path = Plugin::path('TestBake');
     $this->Task->plugin = 'TestBake';
     $this->Task->expects($this->at(0))->method('createFile')->with($this->_normalizePath($path . 'src/Template/Cell/Example/display.ctp'), '');
     $this->Task->expects($this->at(1))->method('createFile')->with($this->_normalizePath($path . 'src/View/Cell/ExampleCell.php'), $this->stringContains('class ExampleCell extends Cell'));
     $result = $this->Task->bake('Example');
     $this->assertSameAsFile(__FUNCTION__ . '.php', $result);
 }
All Usage Examples Of Bake\Shell\Task\TestTask::bake