Skip to content

Commit

Permalink
Merge pull request #417 from loic425/maintenance/php81
Browse files Browse the repository at this point in the history
Testing with PHP 8.1
  • Loading branch information
loic425 committed Apr 25, 2022
2 parents b465e95 + c5d532a commit 60d5f32
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 100 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ["8.0"]
php: ["8.0", "8.1"]
symfony: ["5.4.*"]
node: ["14.x"]
mysql: ["5.7"]
Expand All @@ -32,8 +32,8 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
ini-values: date.timezone=Europe/Warsaw, opcache.enable=1, opcache.enable_cli=1, opcache.memory_consumption=256, opcache.max_accelerated_files=32531, opcache.interned_strings_buffer=8, opcache.validate_timestamps=0, opcache.save_comments=1, opcache.fast_shutdown=0
extensions: intl, gd, opcache, mysql, pdo_mysql, :xdebug
ini-values: date.timezone=Europe/Warsaw, opcache.enable=1, opcache.enable_cli=1, opcache.memory_consumption=512, opcache.max_accelerated_files=65407, opcache.interned_strings_buffer=8, opcache.validate_timestamps=0, opcache.save_comments=1, opcache.fast_shutdown=0
extensions: intl, gd, opcache, mysql, pdo_mysql
tools: symfony
coverage: none

Expand Down Expand Up @@ -94,8 +94,8 @@ jobs:

-
name: Run Psalm
run: make test-psalm
if: always() && steps.end-of-setup.outcome == 'success'
run: vendor/bin/psalm --show-info=false --php-version=${{ matrix.php }}
if: matrix.php != '8.1' && steps.end-of-setup.outcome == 'success'

# -
# name: Run PHPStan
Expand All @@ -112,7 +112,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ["8.0"]
php: ["8.0", "8.1"]
symfony: ["5.4.*"]
node: ["14.x"]
mysql: ["5.7"]
Expand Down Expand Up @@ -142,8 +142,8 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
ini-values: date.timezone=Europe/Paris, opcache.enable=1, opcache.enable_cli=1, opcache.memory_consumption=256, opcache.max_accelerated_files=32531, opcache.interned_strings_buffer=8, opcache.validate_timestamps=0, opcache.save_comments=1, opcache.fast_shutdown=0
extensions: intl, gd, opcache, mysql, pdo_mysql, :xdebug
ini-values: date.timezone=Europe/Paris, opcache.enable=1, opcache.enable_cli=1, opcache.memory_consumption=512, opcache.max_accelerated_files=65407, opcache.interned_strings_buffer=8, opcache.validate_timestamps=0, opcache.save_comments=1, opcache.fast_shutdown=0
extensions: intl, gd, opcache, mysql, pdo_mysql
tools: symfony
coverage: none

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ["8.0"]
php: ["8.0", "8.1"]
symfony: ["5.4.*"]
package: "${{ fromJson(needs.list.outputs.packages) }}"

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
"symfony/web-profiler-bundle": "5.4.*",
"symplify/easy-coding-standard": "^9.0",
"symplify/monorepo-builder": "^8.0",
"vimeo/psalm": "^4.3"
"vimeo/psalm": "^4.22"
},
"conflict": {
"symfony/symfony": "*",
Expand Down
22 changes: 20 additions & 2 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<psalm
errorLevel="5"
resolveFromConfigFile="true"
errorLevel="3"
reportMixedIssues="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand All @@ -16,9 +16,27 @@
<directory name="src/Monofony/MetaPack/AdminMeta/.recipe/spec" />
<directory name="src/Monofony/MetaPack/AdminMeta/.recipe/tests" />
<directory name="src/Monofony/MetaPack/CoreMeta/.recipe/spec" />
<directory name="src/Monofony/MetaPack/FrontMeta/.recipe/tests" />
<directory name="src/Monofony/Bundle/CoreBundle/spec" />
<directory name="src/Monofony/Component/Admin/spec" />
<file name="src/Kernel.php"/>
</ignoreFiles>
</projectFiles>

<issueHandlers>
<ArgumentTypeCoercion errorLevel="info" />
<MoreSpecificReturnType errorLevel="info" />
<PossiblyInvalidArrayAssignment errorLevel="info" />
<PossiblyInvalidArgument errorLevel="info" />
<PossiblyFalseArgument errorLevel="info" />
<PossiblyNullArrayAssignment errorLevel="info" />
<PossiblyNullArgument errorLevel="info" />
<PossiblyNullReference errorLevel="info" />

<ImplementedReturnTypeMismatch>
<errorLevel type="suppress">
<directory name="src/Monofony/MetaPack/CoreMeta/.recipe/src/Factory" />
</errorLevel>
</ImplementedReturnTypeMismatch>
</issueHandlers>
</psalm>
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,13 @@ final class NotificationExpectationMismatchException extends \RuntimeException
public function __construct(
NotificationType $expectedType,
$expectedMessage,
NotificationType $actualType,
$actualMessage,
$code = 0,
\Exception $previous = null
) {
$message = sprintf(
"Expected *%s* notification with a \"%s\" message was not found.\n *%s* notification with a \"%s\" message has been found.",
$expectedType,
$expectedMessage,
$actualType,
$actualMessage
'Expected *%s* notification with a "%s" message was not found',
(string) $expectedType,
$expectedMessage
);

parent::__construct($message, $code, $previous);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(SessionInterface $session, CookieSetterInterface $co
*/
public function logIn(UserInterface $user): void
{
$token = new UsernamePasswordToken($user, $user->getPassword(), $this->firewallContextName, $user->getRoles());
$token = new UsernamePasswordToken($user, $this->firewallContextName, $user->getRoles());
$this->setToken($token);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,63 +13,23 @@

namespace Monofony\Bridge\Behat\Service\Accessor;

use Behat\Mink\Element\NodeElement;
use Behat\Mink\Exception\ElementNotFoundException;
use Behat\Mink\Session;
use Monofony\Bridge\Behat\NotificationType;

final class NotificationAccessor implements NotificationAccessorInterface
{
private Session $session;

public function __construct(Session $session)
{
$this->session = $session;
}

/**
* {@inheritdoc}
*/
public function getMessage()
public function __construct(private Session $session)
{
return $this->getMessageElement()->getText();
}

/**
* {@inheritdoc}
*/
public function getType()
{
if (
$this->getMessageElement()->hasClass('positive')
|| $this->getMessageElement()->hasClass('success')
) {
return NotificationType::success();
}

if (
$this->getMessageElement()->hasClass('negative')
|| $this->getMessageElement()->hasClass('alert')
) {
return NotificationType::failure();
}

throw new \RuntimeException('Cannot resolve notification type');
}

/**
* @return NodeElement
*
* @throws ElementNotFoundException
*/
private function getMessageElement()
public function getMessageElements(): array
{
$messageElement = $this->session->getPage()->find('css', '.sylius-flash-message');
$messageElements = $this->session->getPage()->findAll('css', '.sylius-flash-message');

if (null === $messageElement) {
if (empty($messageElements)) {
throw new ElementNotFoundException($this->session->getDriver(), 'message element', 'css', '.sylius-flash-message');
}

return $messageElement;
return $messageElements;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@

namespace Monofony\Bridge\Behat\Service\Accessor;

use Monofony\Bridge\Behat\NotificationType;
use Behat\Mink\Element\NodeElement;

interface NotificationAccessorInterface
{
/**
* @return string
* @return array|NodeElement[]
*/
public function getMessage();

/**
* @return NotificationType
*/
public function getType();
public function getMessageElements(): array;
}
40 changes: 19 additions & 21 deletions src/Monofony/Bridge/Behat/Service/NotificationChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,41 @@
use Monofony\Bridge\Behat\Exception\NotificationExpectationMismatchException;
use Monofony\Bridge\Behat\NotificationType;
use Monofony\Bridge\Behat\Service\Accessor\NotificationAccessorInterface;
use Webmozart\Assert\Assert;

final class NotificationChecker implements NotificationCheckerInterface
{
private NotificationAccessorInterface $notificationAccessor;

public function __construct(NotificationAccessorInterface $notificationAccessor)
public function __construct(private NotificationAccessorInterface $notificationAccessor)
{
$this->notificationAccessor = $notificationAccessor;
}

/**
* {@inheritdoc}
*/
public function checkNotification($message, NotificationType $type)
{
if ($this->hasType($type) && $this->hasMessage($message)) {
return;
foreach ($this->notificationAccessor->getMessageElements() as $messageElement) {
if (
str_contains($messageElement->getText(), $message) &&
$messageElement->hasClass($this->resolveClass($type))
) {
return;
}
}

throw new NotificationExpectationMismatchException($type, $message, $this->notificationAccessor->getType(), $this->notificationAccessor->getMessage());
throw new NotificationExpectationMismatchException($type, $message);
}

/**
* @return bool
*/
private function hasType(NotificationType $type)
private function resolveClass(NotificationType $type): string
{
return $type === $this->notificationAccessor->getType();
}
$typeClassMap = [
'failure' => 'negative',
'info' => 'info',
'success' => 'positive',
];

/**
* @param string $message
*
* @return bool
*/
private function hasMessage($message)
{
return false !== strpos($this->notificationAccessor->getMessage(), $message);
Assert::keyExists($typeClassMap, $type->__toString());

return $typeClassMap[$type->__toString()];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private function getToken(): string
Assert::notNull($request);

/** @var string $token */
$token = $request->get('token');
$token = $request->attributes->get('token');
Assert::notNull($token);

return $token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private function createEmailQuestion(): Question
/** @var ConstraintViolationListInterface $errors */
$errors = $this->validator->validate((string) $value, [new Email(), new NotBlank()]);
foreach ($errors as $error) {
throw new \DomainException($error->getMessage());
throw new \DomainException((string) $error->getMessage());
}

return $value;
Expand Down Expand Up @@ -153,7 +153,7 @@ private function getPasswordQuestionValidator(): \Closure
/** @var ConstraintViolationListInterface $errors */
$errors = $this->validator->validate($value, [new NotBlank()]);
foreach ($errors as $error) {
throw new \DomainException($error->getMessage());
throw new \DomainException((string) $error->getMessage());
}

return $value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Monofony\Bridge\Behat\Service\AppSecurityServiceInterface;
use Monofony\Bridge\Behat\Service\SharedStorageInterface;
use Monofony\Contracts\Core\Model\User\AppUserInterface;
use Sylius\Component\Customer\Model\CustomerInterface;
use Sylius\Component\User\Repository\UserRepositoryInterface;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -38,13 +39,16 @@ public function iAmLoggedInAs(string $email): void
*/
public function iAmLoggedInAsACustomer(): void
{
/** @var AppUserInterface $user */
$user = $this->userFactory->createOne(['email' => 'customer@example.com', 'password' => 'password', 'roles' => ['ROLE_USER']]);

/** @var AppUserInterface $user */
$user = $this->appUserRepository->find($user->getId());

$this->securityService->logIn($user);

$this->sharedStorage->set('customer', $user->getCustomer());
/** @var CustomerInterface $customer */
$customer = $user->getCustomer();

$this->sharedStorage->set('customer', $customer);
}
}
2 changes: 1 addition & 1 deletion src/Monofony/Pack/TestPack/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"se/selenium-server-standalone": "2.*",
"symfony/debug-bundle": "5.4.*",
"symfony/web-profiler-bundle": "5.4.*",
"vimeo/psalm": "^4.3"
"vimeo/psalm": "^4.22"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down

0 comments on commit 60d5f32

Please sign in to comment.