Skip to content

Commit

Permalink
Merge pull request #20 from spryker-sdk/feature/te-1877/master/add-mi…
Browse files Browse the repository at this point in the history
…ssing-console-test-helper-and-spryk

TE-1877 Added CommunicationTest suite spryks, added ConsoleTest spryk
  • Loading branch information
dereuromark authored Mar 21, 2019
2 parents e386ca9 + aa4ea79 commit 078605d
Show file tree
Hide file tree
Showing 90 changed files with 546 additions and 190 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ composer.phar

tests/_data/emptyFile
tests/_data/vendor/*
tests/_data/src/*
tests/_output
tests/_support/_generated/

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
"post-update-cmd": [
"GitHook\\Composer\\Scripts\\HookInstaller::installGitHook"
],
"cs-check": "phpcs --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml -v src/ tests/ --ignore='/Fixtures/'",
"cs-fix": "phpcbf --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml -v src/ tests/ --ignore='/Fixtures/'",
"cs-check": "phpcs --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml -v src/ tests/ --ignore=/Fixtures,tests/_data/",
"cs-fix": "phpcbf --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml -v src/ tests/ --ignore=/Fixtures,tests/_data/",
"phpstan": "phpstan analyse -l 7 -c phpstan.neon src/"
},
"extra": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ arguments:
preSpryks:
- AddModule

postSpryks:
- AddZedCommunicationConsoleTest
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
spryk: template
description: "Adds a new ConsoleTest to the Zed application."
mode: both

arguments:
module:
inherit: true

organization:
inherit: true
default: Spryker

className:
inherit: true

template:
value: Zed/Communication/ZedCommunicationConsoleTest.php.twig

targetFilename:
value: "{{ className }}ConsoleTest.php"

targetPath:
value: "{{ module }}/tests/{{ organization }}Test/Zed/{{ module }}/Communication/Console/"

preSpryks:
- AddModule

postSpryks:
- AddZedCommunicationTestSuite
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
spryk: structure
description: "Adds a new *module* Communication test suite directory."
mode: both

arguments:
module:
inherit: true

organization:
inherit: true
default: Spryker

targetPath:
value: "{{ module }}/"

directories:
value:
- "tests/{{ organization }}Test/Zed/{{ module }}/Communication/"

postSpryks:
- AddZedCommunicationTestSuiteConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
spryk: update-yml
description: "Updates the *module* test configuration and adds the suite configuration for Communication tests."
mode: both

arguments:
module:
inherit: true

organization:
inherit: true
default: Spryker

template:
value: Zed/Communication/ZedCommunicationTestSuiteCodeceptionConfiguration.yml.twig

afterElement:
value: coverage

addToElement:
value: suites

targetPath:
value: "{{ module }}/tests/{{ organization }}Test/Zed/{{ module }}/codeception.yml"

preSpryks:
- AddZedTestCodeceptionConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ use Symfony\Component\Console\Output\OutputInterface;
/**
* @method \{{ organization }}\Zed\{{ module }}\Business\{{ module }}FacadeInterface getFacade()
*/
class {{ className }}Console extends Console
class {{ className | ensureConsoleSuffix }} extends Console
{
const COMMAND_NAME = '{{ consoleCommand }}';
protected const COMMAND_NAME = '{{ consoleCommand }}';
/**
* @return void
*/
protected function configure(): void
{
$this->setName(static::COMMAND_NAME);
$this->setDescription('ADD DESCRIPTION HERE');
$this
->setName(static::COMMAND_NAME)
->setDescription('ADD DESCRIPTION HERE');
}
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/
namespace {{ organization }}Test\Zed\{{ module }}\Communication\Console;
use Codeception\Test\Unit;
use {{ organization }}\Zed\{{ module }}\Communication\Console\{{ className | ensureConsoleSuffix }};
/**
* Auto-generated group annotations
* @group {{ organization }}Test
* @group Zed
* @group {{ module }}
* @group Communication
* @group Console
* @group {{ className | ensureConsoleSuffix }}Test
* Add your own group annotations below this line
*/
class {{ className | ensureConsoleSuffix }}Test extends Unit
{
/**
* @var \{{ organization }}Test\Zed\{{ module }}\{{ module }}CommunicationTester
*/
protected $tester;
/**
* @return void
*/
public function testExecutes_add_test_info(): void
{
$command = new {{ className | ensureConsoleSuffix }}();
$commandTester = $this->tester->getConsoleTester($command);
$arguments = [
'command' => $command->getName(),
];
$commandTester->execute($arguments);
$this->assertSame({{ className | ensureConsoleSuffix }}::CODE_SUCCESS, $commandTester->getStatusCode());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Communication:
path: Communication
class_name: {{ module }}CommunicationTester
modules:
enabled:
- Asserts
- \SprykerTest\Shared\Testify\Helper\Environment
- \SprykerTest\Shared\Testify\Helper\ConfigHelper
- \SprykerTest\Shared\Testify\Helper\LocatorHelper
- \SprykerTest\Shared\Testify\Helper\DependencyHelper
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace SprykerSdk\Spryk\Model\Spryk\Filter;

class EnsureConsoleSuffixFilter implements FilterInterface
{
public const CONSOLE_SUFFIX = 'Console';

/**
* @return string
*/
public function getName(): string
{
return 'ensureConsoleSuffix';
}

/**
* @param string $value
*
* @return string
*/
public function filter(string $value): string
{
if (mb_substr($value, - mb_strlen(static::CONSOLE_SUFFIX)) !== static::CONSOLE_SUFFIX) {
$value = $value . static::CONSOLE_SUFFIX;
}

return ucfirst($value);
}
}
9 changes: 9 additions & 0 deletions src/SprykerSdk/Spryk/Model/Spryk/Filter/FilterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function getFilterCollection(): array
$this->createCamelBackFilter(),
$this->createClassNameShortFilter(),
$this->createEnsureControllerSuffixFilter(),
$this->createEnsureConsoleSuffixFilter(),
$this->createRemoveControllerSuffixFilter(),
$this->createRemoveActionSuffixFilter(),
$this->createDasherizeFilter(),
Expand Down Expand Up @@ -63,6 +64,14 @@ public function createEnsureControllerSuffixFilter(): FilterInterface
return new EnsureControllerSuffixFilter();
}

/**
* @return \SprykerSdk\Spryk\Model\Spryk\Filter\FilterInterface
*/
public function createEnsureConsoleSuffixFilter(): FilterInterface
{
return new EnsureConsoleSuffixFilter();
}

/**
* @return \SprykerSdk\Spryk\Model\Spryk\Filter\FilterInterface
*/
Expand Down
1 change: 1 addition & 0 deletions tests/SprykerSdkTest/Spryk/Console/SprykDumpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function testDumpsAllSpryks()
$tester->execute($arguments);

$output = $tester->getDisplay();

$this->assertRegExp('/List of all Spryk definitions/', $output);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public function testCreatesModule()
$tester->setInputs(['FooBar', 'Spryker', static::KEY_STROKE_ENTER, static::KEY_STROKE_ENTER, static::KEY_STROKE_ENTER, static::KEY_STROKE_ENTER, static::KEY_STROKE_ENTER]);
$tester->execute($arguments);

static::assertDirectoryExists($this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/src');
$this->assertDirectoryExists($this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/src');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function testTakesDefaultArgumentValueOnEnter()

$output = $tester->getDisplay();
$expectedOutput = 'Enter value for StructureWithDefaultArgumentValue.targetPath argument [vendor/spryker/spryker/Bundles/{{ module }}/]';
static::assertRegExp('#' . preg_quote($expectedOutput) . '#', $output);
$this->assertRegExp('#' . preg_quote($expectedOutput) . '#', $output);

static::assertDirectoryExists($this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/src');
$this->assertDirectoryExists($this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/src');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public function testTakesDefinedArgumentValue()
$tester->execute($arguments);

$output = $tester->getDisplay();
static::assertNotRegExp('/Enter value for module argument/', $output);
$this->assertNotRegExp('/Enter value for module argument/', $output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function testAddsMultiArgument()
$facadeInterfaceContent = file_get_contents($pathToFacadeInterface);
$facadeInterfaceContent = ($facadeInterfaceContent) ?: '';

static::assertRegExp('/\* Specification:/', $facadeInterfaceContent);
static::assertRegExp('/\* - First specification line./', $facadeInterfaceContent);
static::assertRegExp('/\* - Second specification line./', $facadeInterfaceContent);
$this->assertRegExp('/\* Specification:/', $facadeInterfaceContent);
$this->assertRegExp('/\* - First specification line./', $facadeInterfaceContent);
$this->assertRegExp('/\* - Second specification line./', $facadeInterfaceContent);
}
}
6 changes: 3 additions & 3 deletions tests/SprykerSdkTest/Spryk/Console/SprykRunArgumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testAsksForArgumentValue()
$tester->execute($arguments);

$output = $tester->getDisplay();
static::assertRegExp('/Enter value for Structure.module argument/', $output);
$this->assertRegExp('/Enter value for Structure.module argument/', $output);
}

/**
Expand Down Expand Up @@ -84,7 +84,7 @@ public function testAsksMultipleTimesForTheSameArgumentButFirstInputIsTakenAsDef

$output = $tester->getDisplay();

static::assertRegExp('/Enter value for AddModule.module argument/', $output);
static::assertRegExp('/Enter value for AddReadme.module argument \[FooBar\]/', $output);
$this->assertRegExp('/Enter value for AddModule.module argument/', $output);
$this->assertRegExp('/Enter value for AddReadme.module argument \[FooBar\]/', $output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function testDoesNotAskForUserInputWhenAllArgumentsGivenFromUser()

$output = $tester->getDisplay();

static::assertNotRegExp('/Enter value for module argument/', $output);
static::assertNotRegExp('/Enter value for targetPath argument/', $output);
$this->assertNotRegExp('/Enter value for module argument/', $output);
$this->assertNotRegExp('/Enter value for targetPath argument/', $output);

OptionsContainer::clearOptions();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public function testReplacesPlaceholderInArgumentValue()

$tester->execute($arguments);

static::assertDirectoryExists($this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/src');
$this->assertDirectoryExists($this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/src');
}
}
8 changes: 4 additions & 4 deletions tests/SprykerSdkTest/Spryk/Console/SprykRunMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public function testAddsMethod(): void
$tester->execute($arguments);

$targetFile = $this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/src/Spryker/Zed/FooBar/Business/FooBarFacade.php';
static::assertFileExists($targetFile);
$this->assertFileExists($targetFile);
$fileContent = file_get_contents($targetFile);
$fileContent = ($fileContent) ?: '';

static::assertRegExp('/public function/', $fileContent, 'Expected that method was added to target but was not.');
$this->assertRegExp('/public function/', $fileContent, 'Expected that method was added to target but was not.');
}

/**
Expand All @@ -65,11 +65,11 @@ public function testAddsMethodOnlyOnce(): void
$tester->execute($arguments);

$targetFile = $this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/src/Spryker/Zed/FooBar/Business/FooBarFacade.php';
static::assertFileExists($targetFile);
$this->assertFileExists($targetFile);
$fileContent = file_get_contents($targetFile);
$fileContent = ($fileContent) ?: '';

static::assertRegExp('/public function/', $fileContent, 'Expected that method was added to target but was not.');
$this->assertRegExp('/public function/', $fileContent, 'Expected that method was added to target but was not.');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/SprykerSdkTest/Spryk/Console/SprykRunPostSprykTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public function testExecutesPostSprykAfterCalledSpryk()

$tester->execute($arguments);

static::assertDirectoryExists($this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/src');
$this->assertDirectoryExists($this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/src');

static::assertFileExists($this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/README.md');
$this->assertFileExists($this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/README.md');
}
}
6 changes: 3 additions & 3 deletions tests/SprykerSdkTest/Spryk/Console/SprykRunPreSprykTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public function testExecutesPreSprykBeforeCalledSpryk()

$tester->execute($arguments);

static::assertDirectoryExists($this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/firstDirectory');
static::assertDirectoryExists($this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/secondDirectory');
$this->assertDirectoryExists($this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/firstDirectory');
$this->assertDirectoryExists($this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/secondDirectory');

static::assertFileExists($this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/README.md');
$this->assertFileExists($this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/README.md');
}
}
4 changes: 2 additions & 2 deletions tests/SprykerSdkTest/Spryk/Console/SprykRunStructureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testCreatesStructure()

$tester->execute($arguments);

static::assertDirectoryExists($this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/firstDirectory');
static::assertDirectoryExists($this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/secondDirectory');
$this->assertDirectoryExists($this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/firstDirectory');
$this->assertDirectoryExists($this->tester->getRootDirectory() . 'vendor/spryker/spryker/Bundles/FooBar/secondDirectory');
}
}
Loading

0 comments on commit 078605d

Please sign in to comment.