Skip to content

Commit

Permalink
change const values to consts
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jan 3, 2021
1 parent a30864e commit b10a1d9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 31 deletions.
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
PrivatizeFinalClassMethodRector::class => [__DIR__ . '/tests/GitWorkingCopyTest.php'],

// buggy
ChangeReadOnlyVariableWithDefaultValueToConstantRector::class,
// ChangeReadOnlyVariableWithDefaultValueToConstantRector::class,
RemoveUnusedClassConstantRector::class,
]);
};
51 changes: 28 additions & 23 deletions tests/GitWorkingCopyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ final class GitWorkingCopyTest extends AbstractGitWrapperTestCase
*/
private const REMOTE_REPO_DIR = 'build/test/remote';

/**
* @var string
*/
private const DIRECTORY = 'build/tests/wc_init';

/**
* @var string
*/
private const PATCH = <<<CODE_SAMPLE
diff --git a/FileCreatedByPatch.txt b/FileCreatedByPatch.txt
new file mode 100644
index 0000000..dfe437b
--- /dev/null
+++ b/FileCreatedByPatch.txt
@@ -0,0 +1 @@
+contents
CODE_SAMPLE;

/**
* @var string
*/
Expand All @@ -37,14 +56,11 @@ protected function setUp(): void
{
parent::setUp();

// Create the local repository.
// Create the local repository
$this->gitWrapper->init(self::REPO_DIR, [
'bare' => true,
]);

// Clone the local repository.
$directory = 'build/tests/wc_init';
$git = $this->gitWrapper->cloneRepository('file://' . realpath(self::REPO_DIR), $directory);
$git = $this->gitWrapper->cloneRepository('file://' . realpath(self::REPO_DIR), self::DIRECTORY);

// prevent local user.* override
$this->currentUserEmail = $git->config('user.email');
Expand All @@ -54,10 +70,10 @@ protected function setUp(): void
$git->config('user.name', self::CONFIG_NAME);

// Create the initial structure.
FileSystem::write($directory . '/change.me', "unchanged\n");
$this->filesystem->touch($directory . '/move.me');
$this->filesystem->mkdir($directory . '/a.directory', 0755);
$this->filesystem->touch($directory . '/a.directory/remove.me');
FileSystem::write(self::DIRECTORY . '/change.me', "unchanged\n");
$this->filesystem->touch(self::DIRECTORY . '/move.me');
$this->filesystem->mkdir(self::DIRECTORY . '/a.directory', 0755);
$this->filesystem->touch(self::DIRECTORY . '/a.directory/remove.me');

// Initial commit.
$git->add('*');
Expand All @@ -68,7 +84,7 @@ protected function setUp(): void

// Create a branch, add a file.
$branch = 'test-branch';
FileSystem::write($directory . '/branch.txt', $branch . PHP_EOL);
FileSystem::write(self::DIRECTORY . '/branch.txt', $branch . PHP_EOL);
$git->checkoutNewBranch($branch);
$git->add('branch.txt');
$git->commit('Committed testing branch.');
Expand All @@ -80,7 +96,7 @@ protected function setUp(): void
$git->tag('test-tag');
$git->pushTags();

$this->filesystem->remove($directory);
$this->filesystem->remove(self::DIRECTORY);
}

/**
Expand Down Expand Up @@ -189,18 +205,7 @@ public function testGitAdd(): void
public function testGitApply(): void
{
$git = $this->getWorkingCopy();

$patch = <<<CODE_SAMPLE
diff --git a/FileCreatedByPatch.txt b/FileCreatedByPatch.txt
new file mode 100644
index 0000000..dfe437b
--- /dev/null
+++ b/FileCreatedByPatch.txt
@@ -0,0 +1 @@
+contents
CODE_SAMPLE;
FileSystem::write(self::WORKING_DIR . '/patch.txt', $patch);
FileSystem::write(self::WORKING_DIR . '/patch.txt', self::PATCH);
$git->apply('patch.txt');

// PHPUnit 8.5 compatible
Expand Down
26 changes: 19 additions & 7 deletions tests/GitWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,25 @@

final class GitWrapperTest extends AbstractGitWrapperTestCase
{
/**
* @var string
*/
private const BINARY = '/path/to/binary';

/**
* @var string
*/
private const BAD_KEY = './tests/id_rsa_bad';

/**
* @var string
*/
private const BAD_WRAPPER = './tests/dummy-wrapper-bad.sh';

public function testSetGitBinary(): void
{
$binary = '/path/to/binary';
$this->gitWrapper->setGitBinary($binary);
$this->assertSame($binary, $this->gitWrapper->getGitBinary());
$this->gitWrapper->setGitBinary(self::BINARY);
$this->assertSame(self::BINARY, $this->gitWrapper->getGitBinary());
}

public function testSetDispatcher(): void
Expand Down Expand Up @@ -90,15 +104,13 @@ public function testSetPrivateKeyWrapper(): void
public function testSetPrivateKeyError(): void
{
$this->expectException(GitException::class);
$badKey = './tests/id_rsa_bad';
$this->gitWrapper->setPrivateKey($badKey);
$this->gitWrapper->setPrivateKey(self::BAD_KEY);
}

public function testSetPrivateKeyWrapperError(): void
{
$this->expectException(GitException::class);
$badWrapper = './tests/dummy-wrapper-bad.sh';
$this->gitWrapper->setPrivateKey('./tests/id_rsa', 22, $badWrapper);
$this->gitWrapper->setPrivateKey('./tests/id_rsa', 22, self::BAD_WRAPPER);
}

public function testUnsetPrivateKey(): void
Expand Down

0 comments on commit b10a1d9

Please sign in to comment.