Skip to content

Commit

Permalink
Fix behat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
that-guy-iain committed Feb 28, 2024
1 parent af10ca0 commit e03795e
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 138 deletions.
19 changes: 16 additions & 3 deletions tests/Behat/GeneralContext.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
<?php

namespace App\Tests\Behat;
declare(strict_types=1);

use App\Repository\Orm\UserRepository;
/*
* Copyright Humbly Arrogant Software Limited 2020-2024
*
* Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license.
*
* Change Date: 26.06.2026 ( 3 years after 2.2.0 release )
*
* On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
*/

namespace App\Tests\Behat\Skeleton;

use App\Tests\TestKernel;
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Mink\Session;
Expand All @@ -24,6 +36,7 @@ public function __construct(Session $session, EntityManagerInterface $entityMana
*/
public function startUp(BeforeScenarioScope $event)
{
TestKernel::resetParameters();
$em = $this->entityManager;
$metaData = $em->getMetadataFactory()->getAllMetadata();

Expand All @@ -36,4 +49,4 @@ public function startUp(BeforeScenarioScope $event)
}
$this->session->start();
}
}
}
28 changes: 19 additions & 9 deletions tests/Behat/PlanContext.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
<?php

namespace App\Tests\Behat;
declare(strict_types=1);

/*
* Copyright Humbly Arrogant Software Limited 2020-2024
*
* Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license.
*
* Change Date: 26.06.2026 ( 3 years after 2.2.0 release )
*
* On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
*/

namespace App\Tests\Behat\Skeleton;

use Behat\Behat\Context\Context;
use Behat\Mink\Session;
use Doctrine\ORM\EntityManagerInterface;
use Parthenon\Payments\Plan\PlanManager;
use Parthenon\Billing\Plan\PlanManager;

class PlanContext implements Context
{
Expand All @@ -20,7 +31,7 @@ public function __construct(private Session $session, private PlanManager $planM
*/
public function iViewThePlans()
{
$this->sendJsonRequest('GET', '/api/plans');
$this->sendJsonRequest('GET', '/api/billing/plans');
}

/**
Expand All @@ -32,16 +43,15 @@ public function iShouldSeeThePlansThatAreConfigured()

$plans = $this->planManager->getPlans();

foreach ($plans as $plan)
{
foreach ($plans as $plan) {
$name = $plan->getName();
if (!isset($content['plans'][$name])) {
throw new \Exception("Can't see plan ". $name);
throw new \Exception("Can't see plan ".$name);
}

if ($content['plans'][$name]['limits'] != $plan->getLimits()) {
throw new \Exception("Plan for ". $plan->getLimits());
throw new \Exception('Plan for '.$plan->getLimits());
}
}
}
}
}
25 changes: 18 additions & 7 deletions tests/Behat/SendRequestTrait.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<?php

namespace App\Tests\Behat;
declare(strict_types=1);

use Behat\Mink\Session;
use Parthenon\Payments\SessionInterface;
/*
* Copyright Humbly Arrogant Software Limited 2020-2024
*
* Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license.
*
* Change Date: 26.06.2026 ( 3 years after 2.2.0 release )
*
* On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
*/

namespace App\Tests\Behat\Skeleton;

trait SendRequestTrait
{
Expand All @@ -24,17 +33,19 @@ protected function sendJsonRequest(string $method, string $url, array $body = []
[],
[],
$headers,
$jsonBody);
$jsonBody
);
}

protected function getJsonContent() : array
protected function getJsonContent(): array
{
$content = $this->session->getPage()->getContent();
$json = json_decode($content, true);

if (!$json) {
throw new \Exception("No valid JSON found");
throw new \Exception('No valid JSON found');
}

return $json;
}
}
}
31 changes: 26 additions & 5 deletions tests/Behat/TeamContext.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
<?php

namespace App\Tests\Behat;
declare(strict_types=1);

/*
* Copyright Humbly Arrogant Software Limited 2020-2024
*
* Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license.
*
* Change Date: 26.06.2026 ( 3 years after 2.2.0 release )
*
* On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
*/

namespace App\Tests\Behat\Skeleton;

use App\Repository\Orm\InviteCodeRepository;
use App\Repository\Orm\TeamInviteCodeRepository;
use App\Repository\Orm\TeamRepository;
use Behat\Behat\Context\Context;
Expand All @@ -19,7 +30,6 @@ public function __construct(
private TeamRepository $teamRepository,
private TeamInviteCodeRepository $inviteCodeRepository
) {

}

/**
Expand Down Expand Up @@ -72,7 +82,6 @@ public function iCancelTheInviteFor($email)
public function iShouldSeeAsAnInvitedUser($email)
{
$jsonData = json_decode($this->session->getPage()->getContent(), true);

foreach ($jsonData['sent_invites'] as $invite) {
if ($invite['email'] == $email) {
return;
Expand Down Expand Up @@ -111,4 +120,16 @@ public function theInviteForShouldntBeUsable($email)
throw new \Exception('Invite is usable');
}
}
}

/**
* @Then /^I should be told that the email is already a member$/
*/
public function iShouldBeToldThatTheEmailIsAlreadyAMember()
{
$jsonData = json_decode($this->session->getPage()->getContent(), true);

if (!$jsonData['already_a_member']) {
throw new \Exception('Not declared as already a member');
}
}
}
14 changes: 13 additions & 1 deletion tests/Behat/TeamTrait.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<?php

namespace App\Tests\Behat;
declare(strict_types=1);

/*
* Copyright Humbly Arrogant Software Limited 2020-2024
*
* Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license.
*
* Change Date: 26.06.2026 ( 3 years after 2.2.0 release )
*
* On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
*/

namespace App\Tests\Behat\Skeleton;

use App\Entity\Team;

Expand Down
Loading

0 comments on commit e03795e

Please sign in to comment.