Skip to content

Commit

Permalink
Added Fixture generator
Browse files Browse the repository at this point in the history
  • Loading branch information
jamielsharief committed Jul 13, 2020
1 parent d0f763d commit 32a0389
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [3.1.0] - 2020-07-xx

### Added

- Added Fixture generator

## [3.0.1] - 2020-07-09

### Fixed
Expand Down
13 changes: 13 additions & 0 deletions src/Console/Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class GenerateCommand extends Command
'controller' => 'Generates a Controller class',
'entity' => 'Generates an Entity class',
'exception' => 'Generates an Exception class',
'fixture' => 'Generates a Fixture class',
'helper' => 'Generates a Helper class',
'job' => 'Generates a Job class',
'listener' => 'Generates a Listener class',
Expand Down Expand Up @@ -297,6 +298,18 @@ protected function component(array $data)
$data
);
}

protected function fixture(array $data)
{
$baseFolder = dirname($this->getBaseFolder($data['name'], self::TEST));

$this->generate(
$this->getTemplateFilename('fixture'),
$baseFolder . "/Fixture/{$data['class']}Fixture.php",
$data
);
}

protected function helper(array $data)
{
$this->generate(
Expand Down
9 changes: 9 additions & 0 deletions templates/generator/fixture.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
namespace App\Test\Fixture;

use Origin\TestSuite\Fixture;

class %class%Fixture extends Fixture
{
protected $records = [];
}
12 changes: 12 additions & 0 deletions tests/TestCase/Console/Command/GenerateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ public function testGenerateEntity()
unlink($filename);
}

public function testGenerateFixture()
{
$this->exec('generate --force fixture Dummy');
$this->assertExitSuccess();

$filename = TESTS . DS . 'Fixture' . DS . 'DummyFixture.php';
$this->assertOutputContains('Fixture/DummyFixture.php');
$this->assertFileExists($filename);
$this->assertFileHash('df0d25881eee0c6cefb48b1b782890dc', $filename);
unlink($filename);
}

public function testGenerateConcernController()
{
$this->exec('generate --force concern_controller Dummy');
Expand Down

0 comments on commit 32a0389

Please sign in to comment.