-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor code to avoid extending the sebastian/comparator factory
Version 5 of the library makes the Factory class final.
- Loading branch information
Showing
7 changed files
with
77 additions
and
11 deletions.
There are no files selected for viewing
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
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
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,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Prophecy. | ||
* (c) Konstantin Kudryashov <ever.zet@gmail.com> | ||
* Marcello Duarte <marcello.duarte@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Prophecy\Comparator; | ||
|
||
use SebastianBergmann\Comparator\Factory; | ||
|
||
/** | ||
* Prophecy comparator factory. | ||
* | ||
* @author Konstantin Kudryashov <ever.zet@gmail.com> | ||
*/ | ||
final class FactoryProvider | ||
{ | ||
/** | ||
* @var Factory|null | ||
*/ | ||
private static $instance; | ||
|
||
private function __construct() | ||
{ | ||
} | ||
|
||
public static function getInstance(): Factory | ||
{ | ||
if (self::$instance === null) { | ||
self::$instance = new Factory(); | ||
self::$instance->register(new ClosureComparator()); | ||
self::$instance->register(new ProphecyComparator()); | ||
} | ||
|
||
return self::$instance; | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
namespace Tests\Prophecy\Comparator; | ||
|
||
use Prophecy\Comparator\ClosureComparator; | ||
use Prophecy\Comparator\FactoryProvider; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class FactoryProviderTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
function it_should_have_ClosureComparator_registered() | ||
{ | ||
$comparator = FactoryProvider::getInstance()->getComparatorFor(function(){}, function(){}); | ||
|
||
$this->assertInstanceOf(ClosureComparator::class, $comparator); | ||
} | ||
} |