Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Oct 24, 2018
1 parent dd099d3 commit a56d1ab
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions tests/Scoper/ConfigurableScoperTest.php
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);
}
}

0 comments on commit a56d1ab

Please sign in to comment.