Skip to content

Commit 54cc4d5

Browse files
Use webmozart assert in behat tests
1 parent a16f419 commit 54cc4d5

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"behat/behat": "~3.1",
2121
"phpspec/phpspec": "~3.2|~4.0|~5.0|~6.0",
2222
"jackalope/jackalope-doctrine-dbal": "~1.2",
23-
"jackalope/jackalope-jackrabbit": "~1.2"
23+
"jackalope/jackalope-jackrabbit": "~1.2",
24+
"webmozart/assert": "^1.6"
2425
},
2526
"suggest": {
2627
"jackalope/jackalope-doctrine-dbal": "To connect to jackalope doctrine-dbal",

src/PHPCR/Shell/Test/CliContext.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Behat\Behat\Context\SnippetAcceptingContext;
1717
use Behat\Gherkin\Node\PyStringNode;
1818
use Symfony\Component\Filesystem\Filesystem;
19+
use Webmozart\Assert\Assert;
1920

2021
/**
2122
* Features context.
@@ -112,6 +113,6 @@ public function initializeDoctrineDbal()
112113
*/
113114
public function theCommandShouldNotFail()
114115
{
115-
\PHPUnit_Framework_Assert::assertEquals(0, $this->lastExitCode);
116+
Assert::eq(0, $this->lastExitCode);
116117
}
117118
}

src/PHPCR/Shell/Test/ContextBase.php

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use PHPCR\Util\NodeHelper;
2626
use PHPCR\Util\PathHelper;
2727
use Symfony\Component\Filesystem\Filesystem;
28+
use Webmozart\Assert\Assert;
2829

2930
/**
3031
* Features context.
@@ -199,7 +200,7 @@ public function iShouldSeeATableContainingTheFollowingRows(TableNode $table)
199200
}
200201
}
201202

202-
\PHPUnit_Framework_Assert::assertGreaterThanOrEqual(count($expectedRows), $foundRows, $this->getOutput());
203+
Assert::greaterThanEq(count($expectedRows), $foundRows, $this->getOutput());
203204
}
204205

205206
/**
@@ -208,7 +209,7 @@ public function iShouldSeeATableContainingTheFollowingRows(TableNode $table)
208209
public function iShouldSeeTheFollowing(PyStringNode $string)
209210
{
210211
$output = $this->getOutput();
211-
\PHPUnit_Framework_Assert::assertContains($string->getRaw(), $output);
212+
Assert::contains($string->getRaw(), $output);
212213
}
213214

214215
/**
@@ -217,7 +218,7 @@ public function iShouldSeeTheFollowing(PyStringNode $string)
217218
public function iShouldNotSeeTheFollowing(PyStringNode $string)
218219
{
219220
$output = $this->getOutput();
220-
\PHPUnit_Framework_Assert::assertNotContains($string->getRaw(), $output);
221+
Assert::notContains($string->getRaw(), $output);
221222
}
222223

223224
/**
@@ -248,7 +249,7 @@ public function theCommandShouldNotFail()
248249
throw new \Exception('Command failed: ('.$exitCode.') '.$this->getOutput());
249250
}
250251

251-
\PHPUnit_Framework_Assert::assertEquals(0, $exitCode, 'Command exited with code: '.$exitCode);
252+
Assert::eq(0, $exitCode, 'Command exited with code: '.$exitCode);
252253
}
253254

254255
/**
@@ -258,7 +259,7 @@ public function theCommandShouldFail()
258259
{
259260
$exitCode = $this->applicationTester->getLastExitCode();
260261

261-
\PHPUnit_Framework_Assert::assertNotEquals(0, $exitCode, 'Command exited with code '.$exitCode);
262+
Assert::notEq(0, $exitCode, 'Command exited with code '.$exitCode);
262263
}
263264

264265
/**
@@ -269,15 +270,15 @@ public function theCommandShouldFailWithMessage($arg1)
269270
$exitCode = $this->applicationTester->getLastExitCode();
270271
$output = $this->getOutput();
271272

272-
\PHPUnit_Framework_Assert::assertEquals($arg1, $output);
273+
Assert::eq($arg1, $output);
273274
}
274275

275276
/**
276277
* @Given /^the file "([^"]*)" should exist$/
277278
*/
278279
public function theFileShouldExist($arg1)
279280
{
280-
\PHPUnit_Framework_Assert::assertTrue(file_exists($this->getWorkingFilePath($arg1)));
281+
Assert::true(file_exists($this->getWorkingFilePath($arg1)));
281282
}
282283

283284
/**
@@ -304,7 +305,7 @@ public function theFileExists($arg1)
304305
public function theOutputShouldContain(PyStringNode $string)
305306
{
306307
foreach ($string->getStrings() as $line) {
307-
\PHPUnit_Framework_Assert::assertContains($line, $this->getOutput());
308+
Assert::contains($line, $this->getOutput());
308309
}
309310
}
310311

@@ -315,7 +316,7 @@ public function theNodeShouldNotExist($arg1)
315316
{
316317
$session = $this->getSession();
317318
$node = $session->getNode($arg1);
318-
\PHPUnit_Framework_Assert::assertNull($node);
319+
Assert::null($node);
319320
}
320321

321322
/**
@@ -326,7 +327,7 @@ public function theXpathCountIsInFile($arg1, $arg2, $arg3)
326327
$xpath = $this->getXPathForFile($arg3);
327328
$res = $xpath->query($arg1);
328329

329-
\PHPUnit_Framework_Assert::assertEquals($arg2, $res->length);
330+
Assert::eq($arg2, $res->length);
330331
}
331332

332333
/**
@@ -363,7 +364,7 @@ public function iShouldNotBeLoggedIntoTheSession()
363364
{
364365
$this->executeCommand('session:info');
365366
$output = $this->getOutput();
366-
\PHPUnit_Framework_Assert::assertRegExp('/live .*no/', $output);
367+
Assert::regex('/live .*no/', $output);
367368
}
368369

369370
/**
@@ -427,7 +428,7 @@ public function thereShouldExistANodeAtBefore($arg1, $arg2)
427428
throw new \Exception('Could not find child node '.$arg1);
428429
}
429430

430-
\PHPUnit_Framework_Assert::assertEquals($arg2, $afterNode->getPath());
431+
Assert::eq($arg2, $afterNode->getPath());
431432
}
432433

433434
/**
@@ -530,7 +531,7 @@ public function thenIShouldBeLoggedInAs($arg1)
530531
$session = $this->getSession();
531532
$userId = $session->getUserID();
532533

533-
\PHPUnit_Framework_Assert::assertEquals($userId, $arg1);
534+
Assert::eq($userId, $arg1);
534535
}
535536

536537
/**
@@ -690,7 +691,7 @@ public function theCurrentNodeShouldBe($arg1)
690691
{
691692
$this->executeCommand('shell:path:show');
692693
$cnp = $this->applicationTester->getLastLine();
693-
\PHPUnit_Framework_Assert::assertEquals($arg1, $cnp, 'Current path is '.$arg1);
694+
Assert::eq($arg1, $cnp, 'Current path is '.$arg1);
694695
}
695696

696697
/**
@@ -728,7 +729,7 @@ public function thePrimaryTypeOfShouldBe($arg1, $arg2)
728729
$session = $this->getSession();
729730
$node = $session->getNode($arg1);
730731
$primaryTypeName = $node->getPrimaryNodeType()->getName();
731-
\PHPUnit_Framework_Assert::assertEquals($arg2, $primaryTypeName, 'Node type of '.$arg1.' is '.$arg2);
732+
Assert::eq($arg2, $primaryTypeName, 'Node type of '.$arg1.' is '.$arg2);
732733
}
733734

734735
/**
@@ -745,7 +746,7 @@ public function theNodeAtShouldHaveThePropertyWithValue($arg1, $arg2, $arg3)
745746
$propertyValue = $propertyValue->getIdentifier();
746747
}
747748

748-
\PHPUnit_Framework_Assert::assertEquals($arg3, $propertyValue);
749+
Assert::eq($arg3, $propertyValue);
749750
}
750751

751752
/**
@@ -761,7 +762,7 @@ public function theNodeAtShouldHaveThePropertyWithValueAtIndex($arg1, $arg2, $ar
761762
}
762763

763764
$propertyType = $property->getValue();
764-
\PHPUnit_Framework_Assert::assertEquals($arg3, $propertyType[$index]);
765+
Assert::eq($arg3, $propertyType[$index]);
765766
}
766767

767768
/**
@@ -777,7 +778,7 @@ public function thePropertyShouldHaveType($arg1, $arg2)
777778
));
778779
}
779780

780-
\PHPUnit_Framework_Assert::assertEquals($arg2, PropertyType::nameFromValue($property->getType()));
781+
Assert::eq($arg2, PropertyType::nameFromValue($property->getType()));
781782
}
782783

783784
/**
@@ -793,8 +794,8 @@ public function thePropertyShouldHaveTypeAndValue($arg1, $arg2, $arg3)
793794
));
794795
}
795796

796-
\PHPUnit_Framework_Assert::assertEquals($arg2, PropertyType::nameFromValue($property->getType()));
797-
\PHPUnit_Framework_Assert::assertEquals($arg3, $property->getValue());
797+
Assert::eq($arg2, PropertyType::nameFromValue($property->getType()));
798+
Assert::eq($arg3, $property->getValue());
798799
}
799800

800801
/**
@@ -864,7 +865,7 @@ public function theNodeShouldBeLocked($arg1)
864865
$lockManager = $workspace->getLockManager();
865866
$isLocked = $lockManager->isLocked($arg1);
866867

867-
\PHPUnit_Framework_Assert::assertTrue($isLocked);
868+
Assert::true($isLocked);
868869
}
869870

870871
/**
@@ -877,7 +878,7 @@ public function theNodeShouldNotBeLocked($arg1)
877878
$lockManager = $workspace->getLockManager();
878879
$isLocked = $lockManager->isLocked($arg1);
879880

880-
\PHPUnit_Framework_Assert::assertFalse($isLocked);
881+
Assert::false($isLocked);
881882
}
882883

883884
/**

0 commit comments

Comments
 (0)