Skip to content

Commit 4778d1e

Browse files
committed
Removed friends-of-behat/phpspec-expect
1 parent 29aaaca commit 4778d1e

File tree

11 files changed

+101
-89
lines changed

11 files changed

+101
-89
lines changed

Behat/Context/AdminContext.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace FSi\Bundle\AdminBundle\Behat\Context;
1313

14+
use Assert\Assertion;
1415
use Behat\Gherkin\Node\TableNode;
1516
use Behat\Mink\Session;
1617
use Doctrine\ORM\EntityManagerInterface;
@@ -63,10 +64,10 @@ public function theFollowingAdminElementsWereRegistered(TableNode $table): void
6364
foreach ($table->getHash() as $serviceRow) {
6465
$id = $serviceRow['Id'];
6566
$class = $serviceRow['Class'];
66-
expect($this->manager->hasElement($id))->toBe(true);
67-
expect($this->manager->getElement($id))->toBeAnInstanceOf($class);
67+
Assertion::true($this->manager->hasElement($id));
68+
Assertion::isInstanceOf($this->manager->getElement($id), $class);
6869
if (true === array_key_exists('Parent', $serviceRow) && '' !== $serviceRow['Parent']) {
69-
expect($this->manager->getElement($id)->getParentId())->toBe($serviceRow['Parent']);
70+
Assertion::same($this->manager->getElement($id)->getParentId(), $serviceRow['Parent']);
7071
}
7172
}
7273
}
@@ -79,8 +80,8 @@ public function elementHaveFollowingOptionsDefined(AbstractElement $adminElement
7980
foreach ($options->getHash() as $optionRow) {
8081
$option = $optionRow['Option'];
8182
$value = $optionRow['Value'];
82-
expect($adminElement->hasOption($option))->toBe(true);
83-
expect($adminElement->getOption($option))->toBe($value);
83+
Assertion::true($adminElement->hasOption($option));
84+
Assertion::eq($adminElement->getOption($option), $value);
8485
}
8586
}
8687

@@ -92,8 +93,8 @@ public function thereAreFollowingAdminElementsAvailable(TableNode $table): void
9293
foreach ($table->getHash() as $elementRow) {
9394
$id = $elementRow['Id'];
9495
$name = $elementRow['Name'];
95-
expect($this->manager->hasElement($id))->toBe(true);
96-
expect($this->manager->getElement($id)->getName())->toBe($name);
96+
Assertion::true($this->manager->hasElement($id));
97+
Assertion::same($this->manager->getElement($id)->getName(), $name);
9798
}
9899
}
99100

@@ -102,23 +103,23 @@ public function thereAreFollowingAdminElementsAvailable(TableNode $table): void
102103
*/
103104
public function iShouldSeeTitleAtTopBar($navbarBrandText): void
104105
{
105-
expect($this->getPage(AdminPanel::class)->getNavbarBrandText())->toBe($navbarBrandText);
106+
Assertion::eq($this->getPage(AdminPanel::class)->getNavbarBrandText(), $navbarBrandText);
106107
}
107108

108109
/**
109110
* @Given I should see :page page header :headerContent
110111
*/
111112
public function iShouldSeePageHeader(Page $page, $headerContent): void
112113
{
113-
expect($page->getHeader())->toBe($headerContent);
114+
Assertion::eq($page->getHeader(), $headerContent);
114115
}
115116

116117
/**
117118
* @Given /^translations are enabled in application$/
118119
*/
119120
public function translationsAreEnabledInApplication(): void
120121
{
121-
expect($this->translator)->toBeAnInstanceOf(TranslatorInterface::class);
122+
Assertion::isInstanceOf($this->translator, TranslatorInterface::class);
122123
}
123124

124125
/**
@@ -127,7 +128,7 @@ public function translationsAreEnabledInApplication(): void
127128
*/
128129
public function iShouldSeeLanguageDropdownButtonInNavigationBarWithText($button): void
129130
{
130-
expect($this->getPage(AdminPanel::class)->getLanguageDropdown()->hasLink($button))->toBe(true);
131+
Assertion::true($this->getPage(AdminPanel::class)->getLanguageDropdown()->hasLink($button));
131132
}
132133

133134
/**
@@ -138,7 +139,7 @@ public function languageDropdownButtonShouldHaveFollowingLinks(TableNode $dropdo
138139
$links = $this->getPage(AdminPanel::class)->getLanguageDropdownOptions();
139140

140141
foreach ($dropdownLinks->getHash() as $link) {
141-
expect($links)->toContain($link['Link']);
142+
Assertion::inArray($link['Link'], $links);
142143
}
143144
}
144145

Behat/Context/DataContext.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace FSi\Bundle\AdminBundle\Behat\Context;
1313

14+
use Assert\Assertion;
1415
use Behat\Gherkin\Node\TableNode;
1516
use Behat\Mink\Session;
1617
use DateTime;
@@ -29,7 +30,6 @@
2930

3031
use function array_key_exists;
3132
use function count;
32-
use function expect;
3333
use function file_exists;
3434

3535
class DataContext extends AbstractContext
@@ -99,6 +99,8 @@ public function entityToClassName(string $entityName): string
9999
return Subscriber::class;
100100
case 'person':
101101
return Person::class;
102+
default:
103+
throw new InvalidArgumentException(sprintf('Unknown entity name "%s"', $entityName));
102104
}
103105
}
104106

@@ -118,7 +120,7 @@ public function thereIsNumberOfEntities(int $count, string $className): void
118120

119121
$entityManager->flush();
120122

121-
expect(count($this->getRepository($className)->findAll()))->toBe($count);
123+
Assertion::count($this->getRepository($className)->findAll(), $count);
122124
}
123125

124126
/**
@@ -138,23 +140,23 @@ public function thereIsAnEntityWithField(string $className, string $field, $valu
138140
$entityManager->persist($instance);
139141
$entityManager->flush();
140142

141-
expect($this->getRepository($className)->findOneBy([$field => $value]))->toBeAnInstanceOf($className);
143+
Assertion::isInstanceOf($this->getRepository($className)->findOneBy([$field => $value]), $className);
142144
}
143145

144146
/**
145147
* @Then there should be a :className with :field :value present in the database
146148
*/
147149
public function entityWithFieldShouldExist(string $className, string $field, $value): void
148150
{
149-
expect($this->getRepository($className)->findOneBy([$field => $value]))->toBeAnInstanceOf($className);
151+
Assertion::isInstanceOf($this->getRepository($className)->findOneBy([$field => $value]), $className);
150152
}
151153

152154
/**
153155
* @Given :className with :field :value should not exist in database anymore
154156
*/
155157
public function entityShouldNotExistInDatabaseAnymore(string $className, string $field, $value): void
156158
{
157-
expect($this->getRepository($className)->findOneBy([$field => $value]))->toBe(null);
159+
Assertion::null($this->getRepository($className)->findOneBy([$field => $value]));
158160
}
159161

160162
/**
@@ -178,7 +180,7 @@ public function thereShouldNotBeAnyEntities(string $className): void
178180
*/
179181
public function thereShouldExistsNumberOfEntities($count, string $className): void
180182
{
181-
expect(count($this->getRepository($className)->findAll()))->toBe($count);
183+
Assertion::count($this->getRepository($className)->findAll(), $count);
182184
}
183185

184186
/**
@@ -237,7 +239,7 @@ public function entityShouldHaveElementsInCollection(
237239
$entity = $this->getRepository($className)->findOneBy([$field => $value]);
238240
$this->getEntityManager()->refresh($entity);
239241

240-
expect(count($this->getEntityField($entity, $collectionName)))->toBe($expectedCount);
242+
Assertion::count($this->getEntityField($entity, $collectionName), $expectedCount);
241243
}
242244

243245
/**
@@ -248,7 +250,7 @@ public function entityWithIdShouldHaveChangedField(string $className, $id, strin
248250
$entity = $this->getRepository($className)->find($id);
249251
$this->getEntityManager()->refresh($entity);
250252

251-
expect($this->getEntityField($entity, $field))->toBe($value);
253+
Assertion::eq($this->getEntityField($entity, $field), $value);
252254
}
253255

254256
/**
@@ -259,7 +261,7 @@ public function entityWithIdShouldNotHaveChangedFieldValue(string $className, $i
259261
$entity = $this->getRepository($className)->find($id);
260262
$this->getEntityManager()->refresh($entity);
261263

262-
expect($this->getEntityField($entity, $field))->notToBe($value);
264+
Assertion::notEq($this->getEntityField($entity, $field), $value);
263265
}
264266

265267
/**

Behat/Context/DisplayContext.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace FSi\Bundle\AdminBundle\Behat\Context;
1313

14+
use Assert\Assertion;
1415
use Behat\Gherkin\Node\TableNode;
1516
use FSi\Bundle\AdminBundle\Behat\Element\Display;
1617

@@ -23,7 +24,7 @@ public function iShouldSeeDisplayWithFollowingFields(TableNode $table): void
2324
{
2425
$display = $this->getElement(Display::class);
2526
foreach ($table->getHash() as $row) {
26-
expect($display->hasFieldWithName($row['Field name']))->toBe(true);
27+
Assertion::true($display->hasFieldWithName($row['Field name']), true);
2728
}
2829
}
2930
}

Behat/Context/FiltersContext.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace FSi\Bundle\AdminBundle\Behat\Context;
1313

14+
use Assert\Assertion;
1415
use Behat\Gherkin\Node\TableNode;
1516
use FSi\Bundle\AdminBundle\Admin\CRUD\ListElement as AdminListElement;
1617
use FSi\Bundle\AdminBundle\Behat\Element\Filters;
@@ -31,7 +32,7 @@ class FiltersContext extends AbstractContext
3132
*/
3233
public function elementDatasourceMaxResultsIsSet(AdminListElement $adminElement, $maxResults): void
3334
{
34-
expect($this->getDataSource($adminElement)->getMaxResults())->toBe($maxResults);
35+
Assertion::eq($this->getDataSource($adminElement)->getMaxResults(), $maxResults);
3536
}
3637

3738
/**
@@ -41,7 +42,7 @@ public function elementHaveDatasourceWithFields(AdminListElement $adminElement):
4142
{
4243
$dataSource = $this->getDataSource($adminElement);
4344

44-
expect(count($dataSource->getFields()) > 0)->toBe(true);
45+
Assertion::true(count($dataSource->getFields()) > 0);
4546
}
4647

4748
/**
@@ -58,15 +59,15 @@ public function elementHaveDatasourceWithoutFilters(AdminListElement $adminEleme
5859
break;
5960
}
6061
}
61-
expect($filters)->toBe(false);
62+
Assertion::false($filters);
6263
}
6364

6465
/**
6566
* @Then /^both sorting buttons in column header "([^"]*)" should be active$/
6667
*/
6768
public function bothSortingButtonsInColumnHeaderShouldBeActive($column): void
6869
{
69-
expect($this->getListElement()->isColumnAscSortActive($column))->toBe(true);
70+
Assertion::true($this->getListElement()->isColumnAscSortActive($column));
7071
}
7172

7273
/**
@@ -86,10 +87,10 @@ public function buttonInColumnHeaderShouldBeDisabled($sort, $column): void
8687

8788
switch (strtolower($sort)) {
8889
case 'sort asc':
89-
expect($list->isColumnAscSortActive($column))->toBe(false);
90+
Assertion::false($list->isColumnAscSortActive($column));
9091
break;
9192
case 'sort desc':
92-
expect($list->isColumnDescSortActive($column))->toBe(false);
93+
Assertion::false($list->isColumnDescSortActive($column));
9394
break;
9495
default:
9596
throw new \LogicException(sprintf('Unknown sorting type %s', $sort));
@@ -105,10 +106,10 @@ public function buttonInColumnHeaderShouldBeActive($sort, $column): void
105106

106107
switch (strtolower($sort)) {
107108
case 'sort asc':
108-
expect($list->isColumnAscSortActive($column))->toBe(true);
109+
Assertion::true($list->isColumnAscSortActive($column));
109110
break;
110111
case 'sort desc':
111-
expect($list->isColumnDescSortActive($column))->toBe(true);
112+
Assertion::true($list->isColumnDescSortActive($column));
112113
break;
113114
default:
114115
throw new \LogicException(sprintf('Unknown sorting type %s', $sort));
@@ -128,31 +129,31 @@ public function iChangeElementsPerPageTo($elementsCount): void
128129
*/
129130
public function iShouldNotSeeAnyFilters(): void
130131
{
131-
expect($this->getSession()->getPage()->find('css', 'form.filters'))->toBe(null);
132+
Assertion::null($this->getSession()->getPage()->find('css', 'form.filters'));
132133
}
133134

134135
/**
135136
* @Then /^I should see simple text filter "([^"]*)"$/
136137
*/
137138
public function iShouldSeeSimpleTextFilter($filterName): void
138139
{
139-
expect($this->getFiltersElement()->hasFilter($filterName))->toBe(true);
140+
Assertion::true($this->getFiltersElement()->hasFilter($filterName));
140141
}
141142

142143
/**
143144
* @Given /^I should see between filter "([^"]*)" with "([^"]*)" and "([^"]*)" simple text fields$/
144145
*/
145146
public function iShouldSeeBetweenFilterWithAndSimpleTextFields($filterName, $fromName, $toName): void
146147
{
147-
expect($this->getFiltersElement()->hasBetweenFilter($filterName, $fromName, $toName))->toBe(true);
148+
Assertion::true($this->getFiltersElement()->hasBetweenFilter($filterName, $fromName, $toName));
148149
}
149150

150151
/**
151152
* @Given /^I should see choice filter "([^"]*)"$/
152153
*/
153154
public function iShouldSeeChoiceFilter($filterName): void
154155
{
155-
expect($this->getFiltersElement()->hasChoiceFilter($filterName))->toBe(true);
156+
Assertion::true($this->getFiltersElement()->hasChoiceFilter($filterName));
156157
}
157158

158159
/**
@@ -184,26 +185,26 @@ public function iPressSearchButton(): void
184185
*/
185186
public function simpleTextFilterShouldBeFilledWithValue($filterName, $filterValue): void
186187
{
187-
expect($this->getFiltersElement()->getFilerValue($filterName))->toBe($filterValue);
188+
Assertion::eq($this->getFiltersElement()->getFilerValue($filterName), $filterValue);
188189
}
189190

190191
/**
191192
* @Given /^choice filter "([^"]*)" should have value "([^"]*)" selected$/
192193
*/
193194
public function choiceFilterShouldHaveValueSelected($filterName, $choice): void
194195
{
195-
expect($this->getFiltersElement()->getFilterOption($filterName))->toBe($choice);
196+
Assertion::eq($this->getFiltersElement()->getFilterOption($filterName), $choice);
196197
}
197198

198199
/**
199200
* @Then /^I should see actions dropdown with following options$/
200201
*/
201202
public function iShouldSeeActionsDropdownWithFollowingOptions(TableNode $actions): void
202203
{
203-
expect($this->getPage(AdminPanel::class)->hasBatchActionsDropdown())->toBe(true);
204+
Assertion::true($this->getPage(AdminPanel::class)->hasBatchActionsDropdown());
204205

205206
foreach ($actions->getHash() as $actionRow) {
206-
expect($this->getPage(AdminPanel::class)->hasBatchAction($actionRow['Option']))->toBe(true);
207+
Assertion::true($this->getPage(AdminPanel::class)->hasBatchAction($actionRow['Option']));
207208
}
208209
}
209210

0 commit comments

Comments
 (0)