Skip to content

Commit

Permalink
Fix Psalm errors in Behat files
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Jan 24, 2024
1 parent 80f1a80 commit ce286d5
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 98 deletions.
1 change: 0 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<directory name="tests"/>
<ignoreFiles>
<directory name="tests/Application"/>
<directory name="tests/Behat"/>
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
Expand Down
58 changes: 28 additions & 30 deletions tests/Behat/Context/Setup/ProductCalloutContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,16 @@
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Webmozart\Assert\Assert;

final class ProductCalloutContext implements Context
{
/** @var CalloutRuleFactoryInterface */
private $calloutRuleFactory;

/** @var FactoryInterface */
private $calloutFactory;

/** @var ObjectManager */
private $objectManager;

/** @var SharedStorageInterface */
private $sharedStorage;

public function __construct(
CalloutRuleFactoryInterface $calloutRuleFactory,
FactoryInterface $calloutFactory,
ObjectManager $objectManager,
SharedStorageInterface $sharedStorage,
private readonly CalloutRuleFactoryInterface $calloutRuleFactory,
private readonly FactoryInterface $calloutFactory,
private readonly ObjectManager $objectManager,
private readonly SharedStorageInterface $sharedStorage,

Check failure on line 25 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:25:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 25 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:25:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 25 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~6.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:25:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 25 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~5.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:25:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 25 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~5.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:25:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 25 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~5.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:25:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 25 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~5.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:25:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)
) {
$this->calloutRuleFactory = $calloutRuleFactory;
$this->calloutFactory = $calloutFactory;
$this->objectManager = $objectManager;
$this->sharedStorage = $sharedStorage;
}

/**
Expand Down Expand Up @@ -111,24 +96,37 @@ private function createCallout(string $name, string $html, ChannelInterface $cha
$callout = $this->calloutFactory->createNew();
$this->sharedStorage->set('callout', $callout);

Check failure on line 97 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:97:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 97 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:97:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 97 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~6.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:97:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 97 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~5.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:97:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 97 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~5.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:97:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 97 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~5.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:97:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 97 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~5.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:97:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

if (null === $channel && $this->sharedStorage->has('channel')) {
$channel = $this->sharedStorage->get('channel');
$channel = $channel ?? $this->getChannel();

if (null !== $channel) {
$callout->addChannel($channel);

foreach ($channel->getLocales() as $locale) {
$callout->setCurrentLocale((string) $locale->getCode());
$callout->setFallbackLocale((string) $locale->getCode());

$callout->setName($name);
$callout->setText($html);
}
}

$callout->setCode(StringInflector::nameToCode($name));
$callout->setPosition(CalloutInterface::POSITION_TOP_LEFT);
$callout->setPosition('top_left');
$callout->setPriority(0);
$callout->addChannel($channel);
$callout->setEnabled(true);

foreach ($channel->getLocales() as $locale) {
$callout->setCurrentLocale($locale->getCode());
$callout->setFallbackLocale($locale->getCode());
return $callout;
}

$callout->setName($name);
$callout->setText($html);
private function getChannel(): ?ChannelInterface
{
if (!$this->sharedStorage->has('channel')) {

Check failure on line 123 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:123:14: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 123 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:123:14: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 123 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~6.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:123:14: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 123 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~5.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:123:14: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 123 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~5.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:123:14: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 123 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~5.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:123:14: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 123 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~5.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:123:14: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)
return null;
}

return $callout;
$channel = $this->sharedStorage->get('channel');

Check failure on line 127 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:127:20: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 127 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:127:20: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 127 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~6.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:127:20: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 127 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~5.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:127:20: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 127 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~5.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:127:20: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 127 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~5.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:127:20: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)

Check failure on line 127 in tests/Behat/Context/Setup/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~5.4.0)

UndefinedClass

tests/Behat/Context/Setup/ProductCalloutContext.php:127:20: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\SharedStorageInterface does not exist (see https://psalm.dev/019)
Assert::isInstanceOf($channel, ChannelInterface::class);

return $channel;
}
}
21 changes: 6 additions & 15 deletions tests/Behat/Context/Transform/CalloutContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@
namespace Tests\Setono\SyliusCalloutPlugin\Behat\Context\Transform;

use Behat\Behat\Context\Context;
use Setono\SyliusCalloutPlugin\Model\CalloutInterface;
use Setono\SyliusCalloutPlugin\Repository\CalloutRepositoryInterface;
use Webmozart\Assert\Assert;

final class CalloutContext implements Context
{
/** @var CalloutRepositoryInterface */
private $calloutRepository;

public function __construct(CalloutRepositoryInterface $calloutRepository)
public function __construct(private readonly CalloutRepositoryInterface $calloutRepository)
{
$this->calloutRepository = $calloutRepository;
}

/**
* @Transform /^callout "([^"]+)"$/
* @Transform /^"([^"]+)" callout/
* @Transform :callout
*/
public function getCalloutByName($calloutName)
public function getCalloutByName(string $calloutName): CalloutInterface
{
$callouts = $this->calloutRepository->findByName($calloutName);
$callouts = $this->calloutRepository->findBy([
'name' => $calloutName,
]);

Assert::eq(
count($callouts),
Expand All @@ -35,12 +34,4 @@ public function getCalloutByName($calloutName)

return $callouts[0];
}

/**
* @Transform all callouts
*/
public function getAllChannels()
{
return $this->channelRepository->findAll();
}
}
27 changes: 6 additions & 21 deletions tests/Behat/Context/Ui/Admin/ProductCalloutContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,10 @@

final class ProductCalloutContext implements Context
{
/** @var CreatePageInterface */
private $createPage;

private $notificationChecker;

public function __construct(
CreatePageInterface $createPage,
NotificationCheckerInterface $notificationChecker,
private readonly CreatePageInterface $createPage,

Check failure on line 15 in tests/Behat/Context/Ui/Admin/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)

MissingDependency

tests/Behat/Context/Ui/Admin/ProductCalloutContext.php:15:9: MissingDependency: Tests\Setono\SyliusCalloutPlugin\Behat\Page\Admin\ProductCallout\CreatePageInterface depends on class or interface sylius\behat\page\admin\crud\createpageinterface that does not exist (see https://psalm.dev/157)

Check failure on line 15 in tests/Behat/Context/Ui/Admin/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)

MissingDependency

tests/Behat/Context/Ui/Admin/ProductCalloutContext.php:15:9: MissingDependency: Tests\Setono\SyliusCalloutPlugin\Behat\Page\Admin\ProductCallout\CreatePageInterface depends on class or interface sylius\behat\page\admin\crud\createpageinterface that does not exist (see https://psalm.dev/157)

Check failure on line 15 in tests/Behat/Context/Ui/Admin/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~6.4.0)

MissingDependency

tests/Behat/Context/Ui/Admin/ProductCalloutContext.php:15:9: MissingDependency: Tests\Setono\SyliusCalloutPlugin\Behat\Page\Admin\ProductCallout\CreatePageInterface depends on class or interface sylius\behat\page\admin\crud\createpageinterface that does not exist (see https://psalm.dev/157)

Check failure on line 15 in tests/Behat/Context/Ui/Admin/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~5.4.0)

MissingDependency

tests/Behat/Context/Ui/Admin/ProductCalloutContext.php:15:9: MissingDependency: Tests\Setono\SyliusCalloutPlugin\Behat\Page\Admin\ProductCallout\CreatePageInterface depends on class or interface sylius\behat\page\admin\crud\createpageinterface that does not exist (see https://psalm.dev/157)

Check failure on line 15 in tests/Behat/Context/Ui/Admin/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~5.4.0)

MissingDependency

tests/Behat/Context/Ui/Admin/ProductCalloutContext.php:15:9: MissingDependency: Tests\Setono\SyliusCalloutPlugin\Behat\Page\Admin\ProductCallout\CreatePageInterface depends on class or interface sylius\behat\page\admin\crud\createpageinterface that does not exist (see https://psalm.dev/157)

Check failure on line 15 in tests/Behat/Context/Ui/Admin/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~5.4.0)

MissingDependency

tests/Behat/Context/Ui/Admin/ProductCalloutContext.php:15:9: MissingDependency: Tests\Setono\SyliusCalloutPlugin\Behat\Page\Admin\ProductCallout\CreatePageInterface depends on class or interface sylius\behat\page\admin\crud\createpageinterface that does not exist (see https://psalm.dev/157)

Check failure on line 15 in tests/Behat/Context/Ui/Admin/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~5.4.0)

MissingDependency

tests/Behat/Context/Ui/Admin/ProductCalloutContext.php:15:9: MissingDependency: Tests\Setono\SyliusCalloutPlugin\Behat\Page\Admin\ProductCallout\CreatePageInterface depends on class or interface sylius\behat\page\admin\crud\createpageinterface that does not exist (see https://psalm.dev/157)
private readonly NotificationCheckerInterface $notificationChecker,

Check failure on line 16 in tests/Behat/Context/Ui/Admin/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)

UndefinedClass

tests/Behat/Context/Ui/Admin/ProductCalloutContext.php:16:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\NotificationCheckerInterface does not exist (see https://psalm.dev/019)

Check failure on line 16 in tests/Behat/Context/Ui/Admin/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)

UndefinedClass

tests/Behat/Context/Ui/Admin/ProductCalloutContext.php:16:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\NotificationCheckerInterface does not exist (see https://psalm.dev/019)

Check failure on line 16 in tests/Behat/Context/Ui/Admin/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~6.4.0)

UndefinedClass

tests/Behat/Context/Ui/Admin/ProductCalloutContext.php:16:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\NotificationCheckerInterface does not exist (see https://psalm.dev/019)

Check failure on line 16 in tests/Behat/Context/Ui/Admin/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~5.4.0)

UndefinedClass

tests/Behat/Context/Ui/Admin/ProductCalloutContext.php:16:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\NotificationCheckerInterface does not exist (see https://psalm.dev/019)

Check failure on line 16 in tests/Behat/Context/Ui/Admin/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~5.4.0)

UndefinedClass

tests/Behat/Context/Ui/Admin/ProductCalloutContext.php:16:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\NotificationCheckerInterface does not exist (see https://psalm.dev/019)

Check failure on line 16 in tests/Behat/Context/Ui/Admin/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~5.4.0)

UndefinedClass

tests/Behat/Context/Ui/Admin/ProductCalloutContext.php:16:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\NotificationCheckerInterface does not exist (see https://psalm.dev/019)

Check failure on line 16 in tests/Behat/Context/Ui/Admin/ProductCalloutContext.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~5.4.0)

UndefinedClass

tests/Behat/Context/Ui/Admin/ProductCalloutContext.php:16:9: UndefinedClass: Class, interface or enum named Sylius\Behat\Service\NotificationCheckerInterface does not exist (see https://psalm.dev/019)
) {
$this->createPage = $createPage;
$this->notificationChecker = $notificationChecker;
}

/**
Expand Down Expand Up @@ -80,22 +73,14 @@ public function iNameItIn(string $name): void
$this->createPage->fillName($name);
}

/**
* @When I fill the html with :html
*/
public function iFillTheHtmlWith(string $html): void
{
$this->createPage->fillHtml($html);
}

/**
* @When I add the "Has taxon" rule configured with :arg2 and :arg3
*/
public function iAddTheRuleConfiguredWithAnd(...$taxons): void
public function iAddTheRuleConfiguredWithAnd(string ...$taxons): void
{
$this->createPage->addRule('Has taxon');

$this->createPage->selectAutocompleteRuleOption('taxons', $taxons, true);
$this->createPage->selectAutocompleteRuleOption('taxons', $taxons);
}

/**
Expand All @@ -111,15 +96,15 @@ public function iAddTheRuleConfiguredWithTheProduct(string $productName): void
/**
* @When I add it
*/
public function iAddIt()
public function iAddIt(): void
{
$this->createPage->create();
}

/**
* @Then I should be notified that it has been successfully created
*/
public function iShouldBeNotifiedThatItHasBeenSuccessfullyCreated()
public function iShouldBeNotifiedThatItHasBeenSuccessfullyCreated(): void
{
$this->notificationChecker->checkNotification('has been successfully created.', NotificationType::success());
}
Expand Down
23 changes: 6 additions & 17 deletions tests/Behat/Context/Ui/Shop/ProductContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,28 @@
namespace Tests\Setono\SyliusCalloutPlugin\Behat\Context\Ui\Shop;

use Behat\Behat\Context\Context;
use Setono\SyliusCalloutPlugin\Model\CalloutInterface;
use Setono\SyliusCalloutPlugin\Repository\CalloutRepositoryInterface;
use Sylius\Component\Core\Formatter\StringInflector;
use Tests\Setono\SyliusCalloutPlugin\Behat\Page\Shop\Product\IndexPageInterface;
use Webmozart\Assert\Assert;

final class ProductContext implements Context
{
/** @var IndexPageInterface */
private $indexPage;

/** @var CalloutRepositoryInterface */
private $calloutRepository;

public function __construct(
IndexPageInterface $indexPage,
CalloutRepositoryInterface $calloutRepository,
private readonly IndexPageInterface $indexPage,
private readonly CalloutRepositoryInterface $calloutRepository,
) {
$this->indexPage = $indexPage;
$this->calloutRepository = $calloutRepository;
}

/**
* @Then I should see :count products with callout :name
* @Then I should see :count product with callout :name
*/
public function iShouldSeeProductsWithProductCallout(int $count, string $name)
public function iShouldSeeProductsWithProductCallout(int $count, string $name): void
{
/** @var CalloutInterface $callout */
$callout = $this->calloutRepository->findOneBy([
'code' => StringInflector::nameToCode($name),
]);
$callout = $this->calloutRepository->findOneByCode(StringInflector::nameToCode($name));

Assert::same($this->indexPage->countProductsWithCallouts(strip_tags($callout->getText())), $count);
Assert::notNull($callout);
Assert::same($this->indexPage->countProductsWithCallouts(strip_tags((string) $callout->getText())), $count);
}
}
25 changes: 12 additions & 13 deletions tests/Behat/Page/Admin/ProductCallout/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,28 @@ public function addRule(string $ruleName): void
$this->selectRuleOption('Type', $ruleName);
}

public function selectAutocompleteRuleOption(string $option, $value, bool $multiple = false): void
public function selectAutocompleteRuleOption(string $option, array|string $value): void
{
$option = strtolower(str_replace(' ', '_', $option));

$ruleAutocomplete = $this
->getLastCollectionItem('rules')
->find('css', sprintf('input[type="hidden"][name*="[%s]"]', $option))
->getParent()
?->getParent()
;

if ($multiple && is_array($value)) {
AutocompleteHelper::chooseValues($this->getSession(), $ruleAutocomplete, $value);
Assert::notNull($ruleAutocomplete, sprintf('Could not find autocomplete for option "%s"', $option));

return;
if (is_array($value)) {
AutocompleteHelper::chooseValues($this->getSession(), $ruleAutocomplete, $value);
} else {
AutocompleteHelper::chooseValue($this->getSession(), $ruleAutocomplete, $value);
}

AutocompleteHelper::chooseValue($this->getSession(), $ruleAutocomplete, $value);
}

public function selectRuleOption(string $option, string $value, bool $multiple = false): void
{
$this->getLastCollectionItem('rules')->find('named', ['select', $option])->selectOption($value, $multiple);
$this->getLastCollectionItem('rules')->find('named', ['select', $option])?->selectOption($value, $multiple);
}

protected function getDefinedElements(): array
Expand All @@ -85,13 +85,12 @@ protected function getDefinedElements(): array
];
}

/**
* @return NodeElement[]
*/
private function getCollectionItems(string $collection): array
{
$items = $this->getElement($collection)->findAll('css', 'div[data-form-collection="item"]');

Assert::isArray($items);

return $items;
return $this->getElement($collection)->findAll('css', 'div[data-form-collection="item"]');
}

private function getLastCollectionItem(string $collection): NodeElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ public function fillName(string $name): void;

public function addRule(string $ruleName): void;

public function selectAutocompleteRuleOption(string $option, $value, bool $multiple = false): void;
/**
* @param string[]|string $value
*/
public function selectAutocompleteRuleOption(string $option, array|string $value): void;
}

0 comments on commit ce286d5

Please sign in to comment.