Skip to content

Commit

Permalink
Feature: added support for ulrack/command version 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrankruijter committed Aug 16, 2020
1 parent d44e5ab commit 2564bd6
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 30 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: php
php:
- '7.2'
- '7.3'
- '7.4'

Expand Down
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 1.1.0 - 2020-06-14
## 1.2.0 - 2020-08-16
### Added
- Support for `ulrack/command` version 2.0.

## 1.1.0 - 2020-06-14
### Added
- Ability to clear individual caches.

### Fixed
- Clearing all caches when they are not all loaded.

## 1.0.1 - 2020-06-03

### Fixed
- Compatibility with ulrack/services 2.0

Expand All @@ -23,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The initial implementation of the package.

# Versions
- [1.1.0 > Unreleased](https://github.com/ulrack/kernel/compare/1.1.0...HEAD)
- [1.2.0 > Unreleased](https://github.com/ulrack/kernel/compare/1.2.0...HEAD)
- [1.1.0 > 1.2.0](https://github.com/ulrack/kernel/compare/1.1.0...1.2.0)
- [1.0.1 > 1.1.0](https://github.com/ulrack/kernel/compare/1.0.1...1.1.0)
- [1.0.0 > 1.0.1](https://github.com/ulrack/kernel/compare/1.0.0...1.0.1)
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
"prefer-stable": true,
"minimum-stability": "stable",
"require": {
"php": "^7.2",
"php": "^7.3",
"grizz-it/configuration": "^1.1",
"ulrack/command": "^1.0",
"phpunit/phpunit": "^9.3",
"squizlabs/php_codesniffer": "^3.5",
"ulrack/command": "^2.0",
"ulrack/kernel": "^1.3"
},
"authors": [
Expand Down Expand Up @@ -52,7 +54,5 @@
]
},
"require-dev": {
"phpunit/phpunit": "^8.0",
"squizlabs/php_codesniffer": "^3.4"
}
}
23 changes: 12 additions & 11 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResult="false">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
22 changes: 21 additions & 1 deletion src/Command/CacheClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,18 @@ public function __invoke(
->getCacheFileSystem()
->list('') as $cacheDir
) {
$output->writeLine(
sprintf('Preparing cache directory: %s', $cacheDir),
'text',
true
);
$this->cacheManager->getCache($cacheDir);
}

$output->writeLine(
'Clearing cache directories',
'text',
true
);
$this->cacheManager->getCacheRegistry()->clearAllCaches();
} elseif (is_string($caches) || is_array($caches)) {
$output->writeLine(
Expand All @@ -64,10 +73,21 @@ public function __invoke(
);

foreach ((array) $caches as $cache) {
$output->writeLine(
sprintf('Clearing cache directory: %s', $cache),
'text',
true
);
$this->cacheManager->getCache($cache)->clear();
}
}

$output->writeLine(
'Resetting registered caches.',
'text',
true
);

$this->cacheManager->resetRegisteredCaches();
$output->writeLine('Done.');
}
Expand Down
65 changes: 58 additions & 7 deletions src/Command/ValidateConfigurationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,25 @@ public function __invoke(
$validatorFactory = $this->validationManager->getValidatorFactory();
$errorMessages = [];

foreach ($configRegistry as $configGroup) {
foreach ($configGroup as $entry) {
foreach ($configRegistry as $configGroupKey => $configGroup) {
$output->writeLine(
sprintf('Checking group: %s', $configGroupKey),
'text',
true
);

foreach ($configGroup as $entryKey => $entry) {
if (is_array($entry) && isset($entry['$schema'])) {
$output->writeLine(
sprintf(
'Checking validation for %s with: %s',
$entryKey,
$entry['$schema']
),
'text',
true
);

$validator = $validatorFactory->createFromRemoteFile(
$entry['$schema']
);
Expand All @@ -73,10 +89,18 @@ public function __invoke(
json_decode(json_encode($entry))
)
) {
$output->writeLine(
sprintf('Validation failed for: %s', $entryKey),
'text',
true
);

$errorMessages[] = sprintf(
'Invalid configuration found at: %s',
json_encode($entry, JSON_PRETTY_PRINT)
);

continue;
}
}
}
Expand All @@ -85,15 +109,18 @@ public function __invoke(
$errorMessages = array_merge($errorMessages, $this->specialValidation(
'parameters',
'parameters.schema.json',
$configRegistry
$configRegistry,
$output
), $this->specialValidation(
'services',
'services.schema.json',
$configRegistry
$configRegistry,
$output
), $this->specialValidation(
'preferences',
'preferences.schema.json',
$configRegistry
$configRegistry,
$output
));

if (count($errorMessages) > 0) {
Expand All @@ -115,14 +142,30 @@ public function __invoke(
private function specialValidation(
string $key,
string $schema,
array $configRegistry
array $configRegistry,
OutputInterface $output
): array {
$output->writeLine(
sprintf(
'Running special validation for: %s with %s',
$key,
$schema
),
'text',
true
);
$errorMessages = [];
$validator = $this->validationManager->getValidatorFactory()
->createFromRemoteFile($schema);

if (isset($configRegistry[$key])) {
foreach ($configRegistry[$key] as $entry) {
foreach ($configRegistry[$key] as $entryKey => $entry) {
$output->writeLine(
sprintf('Checking validation for: %s', $entryKey),
'text',
true
);

if (
!$validator->__invoke(
json_decode(json_encode($entry))
Expand All @@ -132,6 +175,14 @@ private function specialValidation(
'Invalid configuration found at: %s',
json_encode($entry, JSON_PRETTY_PRINT)
);

$output->writeLine(
sprintf('Validation failed for: %s', $entryKey),
'text',
true
);

continue;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Command/CacheClearCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testCommand(): void
->withConsecutive(['foo'], ['bar'])
->willReturn($this->createMock(CacheInterface::class));

$output->expects(static::exactly(2))
$output->expects(static::exactly(6))
->method('writeLine');

$cacheManager->expects(static::once())
Expand Down Expand Up @@ -98,7 +98,7 @@ public function testCommandOneEntry(): void
$cache->expects(static::once())
->method('clear');

$output->expects(static::exactly(2))
$output->expects(static::exactly(4))
->method('writeLine');

$cacheManager->expects(static::once())
Expand Down Expand Up @@ -138,7 +138,7 @@ public function testCommandMultiple(): void
$cacheTwo->expects(static::once())
->method('clear');

$output->expects(static::exactly(2))
$output->expects(static::exactly(5))
->method('writeLine');

$cacheManager->expects(static::once())
Expand Down

0 comments on commit 2564bd6

Please sign in to comment.