Skip to content
This repository has been archived by the owner on Jul 23, 2023. It is now read-only.

first tests to introduce #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="tests/bootstrap.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
61 changes: 61 additions & 0 deletions tests/DirectoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Templado\Cli;

use PHPUnit\Framework\TestCase;

/**
* Class RequestTest
* @package Templado\Cli
*
* @covers \Templado\Cli\Directory
*/
class DirectoryTest extends TestCase
{
public function testCanBeCreated()
{
$this->assertInstanceOf(
Directory::class,
new Directory(__DIR__ . '/_data')
);
}

public function testCanBeRetrieved()
{
$directory = new Directory(__DIR__ . '/_data');
$this->assertEquals(__DIR__ . '/_data', $directory->asString());
}

public function testCantBeCreatedOnEmptyArgument()
{
$this->expectException(DirectoryException::class);
new Directory('');
}

public function testCantBeCreatedOnNonExistingDirectory()
{
$this->expectException(DirectoryException::class);
new Directory(__DIR__ . '/DirectoryTest.php');
}

public function testCanGetIterator()
{
$directory = new Directory(__DIR__ . '/_data');
$this->assertInstanceOf(\Traversable::class, $directory->getIterator());
}

public function testCanClear()
{
$tempDir = __DIR__ . '/_fixture/deleteableFiles';

//just to be sure we have a valid fixtuer setup
if (!file_exists($tempDir . '/somefile.txt'))
touch($tempDir . '/somefile.txt');
$this->assertEquals(1, count(scandir($tempDir)) - 2);

$directory = new Directory($tempDir);
$directory->clear();

$this->assertEquals(0, count(scandir($tempDir)) - 2);
}
}
Empty file.
4 changes: 4 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php declare(strict_types=1);

require __DIR__ . '/../src/autoload.php';
require __DIR__ . '/../vendor/autoload.php';