Skip to content
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

test: Add tests for the Pharaoh class #952

Merged
merged 2 commits into from
Mar 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions tests/Pharaoh/PharaohTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

declare(strict_types=1);

/*
* This file is part of the box project.
*
* (c) Kevin Herrera <kevin@herrera.io>
* Théo Fidry <theo.fidry@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace KevinGH\RequirementChecker\Pharaoh;

use KevinGH\Box\Pharaoh\Pharaoh;
use KevinGH\Box\Test\RequiresPharReadonlyOff;
use PHPUnit\Framework\TestCase;

/**
* @covers \KevinGH\Box\Pharaoh\Pharaoh
*
* @internal
*/
final class PharaohTest extends TestCase
{
use RequiresPharReadonlyOff;

private const FIXTURES_DIR = __DIR__.'/../../fixtures/info';

protected function setUp(): void
{
$this->markAsSkippedIfPharReadonlyIsOn();
}

public function test_it_can_be_instantiated(): void
{
$file = self::FIXTURES_DIR.'/simple-phar.phar';
$pharInfo = new Pharaoh($file);

self::assertSame($file, $pharInfo->getFile());
self::assertSame('simple-phar.phar', $pharInfo->getFileName());
}

public function test_it_cleans_itself_up_upon_destruction(): void
{
$pharInfo = new Pharaoh(self::FIXTURES_DIR.'/simple-phar.phar');

$tmp = $pharInfo->getTmp();

self::assertDirectoryExists($tmp);

unset($pharInfo);

self::assertDirectoryDoesNotExist($tmp);
}

public function test_it_can_create_two_instances_of_the_same_phar(): void
{
$file = self::FIXTURES_DIR.'/simple-phar.phar';

$pharInfoA = new Pharaoh($file);
$pharInfoB = new Pharaoh($file);

self::assertNotSame($pharInfoA->getPhar(), $pharInfoB->getPhar());
}
}