-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
107 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the humbug/php-scoper package. | ||
* | ||
* Copyright (c) 2017 Théo FIDRY <[email protected]>, | ||
* Pádraic Brady <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Humbug\PhpScoper\Scoper; | ||
|
||
use Humbug\PhpScoper\Scoper; | ||
use Humbug\PhpScoper\Whitelist; | ||
use PHPUnit\Framework\Assert; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\Argument; | ||
use Prophecy\Prophecy\ObjectProphecy; | ||
|
||
/** | ||
* @covers \Humbug\PhpScoper\Scoper\ConfigurableScoper | ||
*/ | ||
class ConfigurableScoperTest extends TestCase | ||
{ | ||
/** | ||
* @var Scoper|ObjectProphecy | ||
*/ | ||
private $decoratedScoperProphecy; | ||
|
||
/** | ||
* @var Scoper | ||
*/ | ||
private $decoratedScoper; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function setUp() | ||
{ | ||
$this->decoratedScoperProphecy = $this->prophesize(Scoper::class); | ||
$this->decoratedScoper = $this->decoratedScoperProphecy->reveal(); | ||
} | ||
|
||
public function test_is_a_Scoper() | ||
{ | ||
$this->assertTrue(is_a(ConfigurableScoper::class, Scoper::class, true)); | ||
} | ||
|
||
public function test_it_scopes_the_files_with_the_decorated_scoper() | ||
{ | ||
$filePath = '/path/to/file.php'; | ||
$contents = 'Original file content'; | ||
$prefix = 'Humbug'; | ||
$patchers = []; | ||
$whitelist = Whitelist::create(true, true, true, 'Foo'); | ||
|
||
$this->decoratedScoperProphecy | ||
->scope($filePath, $contents, $prefix, $patchers, $whitelist) | ||
->willReturn($expected = 'Decorated scoper contents') | ||
; | ||
|
||
$scoper = new ConfigurableScoper($this->decoratedScoper); | ||
|
||
$actual = $scoper->scope($filePath, $contents, $prefix, $patchers, $whitelist); | ||
|
||
$this->assertSame($expected, $actual); | ||
|
||
$this->decoratedScoperProphecy->scope(Argument::cetera())->shouldHaveBeenCalledTimes(1); | ||
} | ||
|
||
public function test_it_can_create_a_scoper_allowing_to_whitelist_specific_files() | ||
{ | ||
$whitelistedFiles = [ | ||
'/path/to/whitelisted-file-1', | ||
'/path/to/whitelisted-file-2', | ||
]; | ||
|
||
$filePath = '/path/to/file.php'; | ||
$contents = 'Original file content'; | ||
$prefix = 'Humbug'; | ||
$patchers = []; | ||
$whitelist = Whitelist::create(true, true, true, 'Foo'); | ||
|
||
$this->decoratedScoperProphecy | ||
->scope(Argument::any(), $contents, $prefix, $patchers, $whitelist) | ||
->willReturn($expected = 'scoped contents') | ||
; | ||
|
||
$scoper = (new ConfigurableScoper($this->decoratedScoper))->withWhitelistedFiles(...$whitelistedFiles); | ||
|
||
foreach ($whitelistedFiles as $whitelistedFile) { | ||
$actual = $scoper->scope($whitelistedFile, $contents, $prefix, $patchers, $whitelist); | ||
|
||
$this->assertSame($contents, $actual); | ||
} | ||
|
||
$actual = $scoper->scope($filePath, $contents, $prefix, $patchers, $whitelist); | ||
|
||
$this->assertSame($expected, $actual); | ||
|
||
$this->decoratedScoperProphecy->scope(Argument::cetera())->shouldHaveBeenCalledTimes(1); | ||
} | ||
} |