-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.6] Fix #23592 (SeeInOrder) #23594
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c7f6ced
added SeeInOrder PHPUnit constraint to allow assertSeeInOrder and ass…
Jantho1990 057fc16
added test for SeeInOrder
Jantho1990 9740e6a
changed toString() to return the class name
Jantho1990 27ad8db
Added a separate test for assertSeeTextInOrder
Jantho1990 99cb7af
updated to fit with style guide
Jantho1990 533f468
fixed undeclared var in doc block
Jantho1990 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
src/Illuminate/Foundation/Testing/Constraints/SeeInOrder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace Illuminate\Foundation\Testing\Constraints; | ||
|
||
use PHPUnit\Framework\Constraint\Constraint; | ||
|
||
class SeeInOrder extends Constraint | ||
{ | ||
/** | ||
* The value that failed. Used to display in the error message. | ||
* | ||
* @var string | ||
*/ | ||
protected $failedValue; | ||
|
||
/** | ||
* The string we want to check the content of. | ||
* | ||
* @var | ||
*/ | ||
protected $content; | ||
|
||
/** | ||
* Create a new constraint instance. | ||
* | ||
* @param string $content | ||
* @return void | ||
*/ | ||
public function __construct(string $content) | ||
{ | ||
$this->content = $content; | ||
} | ||
|
||
/** | ||
* Check if the data is found in the given table. | ||
* | ||
* @param array $values | ||
* @return bool | ||
*/ | ||
public function matches($values) : bool | ||
{ | ||
$position = 0; | ||
|
||
foreach ($values as $value) { | ||
$valuePosition = mb_strpos($this->content, $value, $position); | ||
|
||
if ($valuePosition === false || $valuePosition < $position) { | ||
$this->failedValue = $value; | ||
|
||
return false; | ||
} | ||
|
||
$position = $valuePosition + mb_strlen($value); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Get the description of the failure. | ||
* | ||
* @param array $values | ||
* @return string | ||
*/ | ||
public function failureDescription($values) : string | ||
{ | ||
return sprintf( | ||
'Failed asserting that \'%s\' contains "%s" in specified order.', | ||
$this->content, | ||
$this->failedValue | ||
); | ||
} | ||
|
||
/** | ||
* Get a string representation of the object. | ||
* | ||
* @return string | ||
*/ | ||
public function toString() : string | ||
{ | ||
$class = new ReflectionClass($this); | ||
|
||
return $class->name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Foundation\Constraints; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Illuminate\Tests\Foundation\FoundationTestResponseTest; | ||
|
||
class SeeInOrderTest extends TestCase | ||
{ | ||
public function testAllSeeInOrderAssertionsDetected() | ||
{ | ||
$test = new FoundationTestResponseTest('testAssertSeeInOrder'); | ||
$test->run(); | ||
// If we get four assertions, that means all of the assertions | ||
// were detected by PHPUnit, which is what we want to know. | ||
// Doing it this way allows the test to work even though | ||
// the global settings don't check for risky tests. | ||
$this->assertEquals($test->getNumAssertions(), 4); | ||
} | ||
|
||
public function testAllSeeTextInOrderAssertionsDetected() | ||
{ | ||
$test = new FoundationTestResponseTest('testAssertSeeTextInOrder'); | ||
$test->run(); | ||
// If we get four assertions, that means all of the assertions | ||
// were detected by PHPUnit, which is what we want to know. | ||
// Doing it this way allows the test to work even though | ||
// the global settings don't check for risky tests. | ||
$this->assertEquals($test->getNumAssertions(), 4); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing
var
type.Strange that Style CI didn't cached it 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a code style bug, that's why. It's just a syntax error.