Skip to content

Commit

Permalink
Merge pull request #44 from kokspflanze/php81-update
Browse files Browse the repository at this point in the history
update tests for laminas-workflow
  • Loading branch information
kokspflanze authored Dec 5, 2021
2 parents c44ad0b + df69897 commit cededa7
Show file tree
Hide file tree
Showing 28 changed files with 244 additions and 333 deletions.
14 changes: 5 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
nbproject
._*
.~lock.*
.buildpath
.DS_Store
.idea
.project
.settings
composer.phar
composer.lock
composer.phar
clover.xml
phpunit.xml
vendor
.idea
.phpunit.result.cache
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
],
"require": {
"php": "^7.3 || ~8.0.0 || ~8.1.0",
"twig/twig": "^3.0.1",
"twig/twig": "^3.3.4",
"laminas/laminas-mvc": "^3.0",
"laminas/laminas-view": "^2.7",
"laminas/laminas-servicemanager": "^3.0",
Expand All @@ -40,7 +40,7 @@
},
"autoload-dev": {
"psr-4": {
"ZfcTwigTest\\": "tests/ZfcTwigTest"
"ZfcTwigTest\\": "test/"
}
},
"require-dev": {
Expand Down Expand Up @@ -68,6 +68,6 @@
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"test": "phpunit --colors=always --configuration tests/phpunit.xml"
"test": "phpunit --colors=always --configuration phpunit.xml.dist"
}
}
8 changes: 8 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<ruleset name="Laminas coding standard">
<rule ref="./vendor/laminas/laminas-coding-standard/src/LaminasCodingStandard/ruleset.xml"/>

<!-- Paths to check -->
<file>src</file>
<file>test</file>
</ruleset>
24 changes: 24 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
verbose="true"
stopOnFailure="false"
processIsolation="false"
backupGlobals="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<clover outputFile="./build/logs/clover.xml"/>
<text outputFile="php://stdout"/>
</report>
</coverage>
<testsuite name="BjyAuthorize tests">
<directory>./test</directory>
</testsuite>
</phpunit>
18 changes: 9 additions & 9 deletions src/Module.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
<?php

declare(strict_types=1);

namespace ZfcTwig;

use InvalidArgumentException;
use Twig\Environment;
use Laminas\EventManager\EventInterface;
use Laminas\ModuleManager\Feature\BootstrapListenerInterface;
use Laminas\ModuleManager\Feature\ConfigProviderInterface;
use function is_string;
use Twig\Environment;

use function is_object;
use function is_string;

class Module implements
BootstrapListenerInterface,
ConfigProviderInterface
{
/**
* @param EventInterface $e
* @throws InvalidArgumentException
* {@inheritDoc}
*/
public function onBootstrap(EventInterface $e): void
public function onBootstrap(EventInterface $event): void
{
/** @var \Laminas\Mvc\MvcEvent $e*/
$application = $e->getApplication();
$application = $event->getApplication();
$serviceManager = $application->getServiceManager();
$environment = $serviceManager->get(Environment::class);

Expand All @@ -39,7 +40,7 @@ public function onBootstrap(EventInterface $e): void
} else {
$extension = new $extension();
}
} elseif (!is_object($extension)) {
} elseif (! is_object($extension)) {
throw new InvalidArgumentException('Extensions should be a string or object.');
}

Expand All @@ -54,5 +55,4 @@ public function getConfig(): array
{
return include __DIR__ . '/../config/module.config.php';
}

}
65 changes: 12 additions & 53 deletions src/ModuleOptions.php
Original file line number Diff line number Diff line change
@@ -1,63 +1,44 @@
<?php

declare(strict_types=1);

namespace ZfcTwig;

use Laminas\Stdlib\AbstractOptions;

class ModuleOptions extends AbstractOptions
{
/**
* @var string
*/
/** @var string */
protected $environmentLoader = '';

/**
* @var string
*/
/** @var string */
protected $environmentClass = '';

/**
* @var array
*/
/** @var array */
protected $environmentOptions = [];

/**
* @var array
*/
/** @var array */
protected $globals = [];

/**
* @var array
*/
/** @var array */
protected $loaderChain = [];

/**
* @var array
*/
/** @var array */
protected $extensions = [];

/**
* @var string
*/
/** @var string */
protected $suffix = '';

/**
* @var bool
*/
/** @var bool */
protected $enableFallbackFunctions = true;

/**
* @var bool
*/
/** @var bool */
protected $disableZfmodel = true;

/**
* @var array
*/
/** @var array */
protected $helperManager = [];

/**
* @param boolean $disableZfmodel
* @return $this
*/
public function setDisableZfmodel(bool $disableZfmodel): self
Expand All @@ -66,16 +47,12 @@ public function setDisableZfmodel(bool $disableZfmodel): self
return $this;
}

/**
* @return boolean
*/
public function getDisableZfmodel(): bool
{
return $this->disableZfmodel;
}

/**
* @param boolean $enableFallbackFunctions
* @return $this
*/
public function setEnableFallbackFunctions(bool $enableFallbackFunctions): self
Expand All @@ -84,16 +61,12 @@ public function setEnableFallbackFunctions(bool $enableFallbackFunctions): self
return $this;
}

/**
* @return boolean
*/
public function getEnableFallbackFunctions(): bool
{
return $this->enableFallbackFunctions;
}

/**
* @param string $environmentLoader
* @return $this
*/
public function setEnvironmentLoader(string $environmentLoader): self
Expand All @@ -102,9 +75,6 @@ public function setEnvironmentLoader(string $environmentLoader): self
return $this;
}

/**
* @return string
*/
public function getEnvironmentLoader(): string
{
return $this->environmentLoader;
Expand Down Expand Up @@ -183,7 +153,6 @@ public function getLoaderChain(): array
}

/**
* @param string $suffix
* @return $this
*/
public function setSuffix(string $suffix): self
Expand All @@ -192,25 +161,16 @@ public function setSuffix(string $suffix): self
return $this;
}

/**
* @return string
*/
public function getSuffix(): string
{
return $this->suffix;
}

/**
* @param string $environmentClass
*/
public function setEnvironmentClass(string $environmentClass)
{
$this->environmentClass = $environmentClass;
}

/**
* @return string
*/
public function getEnvironmentClass(): string
{
return $this->environmentClass;
Expand All @@ -231,5 +191,4 @@ public function getGlobals(): array
{
return $this->globals;
}

}
6 changes: 3 additions & 3 deletions src/ModuleOptionsFactory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace ZfcTwig;

use Interop\Container\ContainerInterface;
Expand All @@ -8,16 +10,14 @@
class ModuleOptionsFactory implements FactoryInterface
{
/**
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
* @return ModuleOptions
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
{
$config = $container->get('config');

return new ModuleOptions($config['zfctwig'] ?? []);
}

}
13 changes: 7 additions & 6 deletions src/Twig/ChainLoaderFactory.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
<?php

declare(strict_types=1);

namespace ZfcTwig\Twig;

use Interop\Container\ContainerInterface;
use InvalidArgumentException;
use Twig\Loader;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Twig\Loader;
use ZfcTwig\ModuleOptions;

use function is_string;

class ChainLoaderFactory implements FactoryInterface
{
/**
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
* @return Loader\ChainLoader
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
{
/** @var ModuleOptions $options */
$options = $container->get(ModuleOptions::class);
Expand All @@ -26,13 +28,12 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
$chain = new Loader\ChainLoader();

foreach ($options->getLoaderChain() as $loader) {
if (!is_string($loader) || !$container->has($loader)) {
if (! is_string($loader) || ! $container->has($loader)) {
throw new InvalidArgumentException('Loaders should be a service manager alias.');
}
$chain->addLoader($container->get($loader));
}

return $chain;
}

}
}
Loading

0 comments on commit cededa7

Please sign in to comment.