-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Finder] Make Comparator immutable #42137
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,13 +12,21 @@ | |
namespace Symfony\Component\Finder\Tests\Comparator; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; | ||
use Symfony\Component\Finder\Comparator\Comparator; | ||
|
||
class ComparatorTest extends TestCase | ||
{ | ||
use ExpectDeprecationTrait; | ||
|
||
/** | ||
* @group legacy | ||
*/ | ||
public function testGetSetOperator() | ||
{ | ||
$comparator = new Comparator(); | ||
$comparator = new Comparator('some target'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have 2 tests in one here. Those should be split (which will also allow using And the test about an invalid operator should also be added for the constructor. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
$this->expectDeprecation('Since symfony/finder 5.4: "Symfony\Component\Finder\Comparator\Comparator::setOperator" is deprecated. Set the operator via the constructor instead.'); | ||
$comparator->setOperator('>'); | ||
$this->assertEquals('>', $comparator->getOperator(), '->getOperator() returns the current operator'); | ||
} | ||
|
@@ -32,9 +40,16 @@ public function testInvalidOperator() | |
$comparator->setOperator('foo'); | ||
} | ||
|
||
|
||
/** | ||
* @group legacy | ||
*/ | ||
public function testGetSetTarget() | ||
{ | ||
$this->expectDeprecation('Since symfony/finder 5.4: Constructing a "Symfony\Component\Finder\Comparator\Comparator" without setting "$target" is deprecated.'); | ||
$comparator = new Comparator(); | ||
|
||
$this->expectDeprecation('Since symfony/finder 5.4: "Symfony\Component\Finder\Comparator\Comparator::setTarget" is deprecated. Set the target via the constructor instead.'); | ||
$comparator->setTarget(8); | ||
$this->assertEquals(8, $comparator->getTarget(), '->getTarget() returns the target'); | ||
} | ||
|
@@ -44,9 +59,10 @@ public function testGetSetTarget() | |
*/ | ||
public function testTestSucceeds(string $operator, string $target, string $testedValue) | ||
{ | ||
$c = new Comparator(); | ||
$c->setOperator($operator); | ||
$c->setTarget($target); | ||
$c = new Comparator($target, $operator); | ||
|
||
$this->assertSame($target, $c->getTarget()); | ||
$this->assertSame($operator, $c->getOperator()); | ||
|
||
$this->assertTrue($c->test($testedValue)); | ||
} | ||
|
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.
did you change ?? to ?: on purpose?
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.
Yes.
setOperator()
accepted an empty string and I've made the constructor stricter in that regard.