Skip to content

Commit

Permalink
Merge pull request #117 from nikolaystrikhar/add-firsts-tests-for-dis…
Browse files Browse the repository at this point in the history
…covered-files

Tests: Add first tests for DiscoveredFiles.php
  • Loading branch information
BrianHenryIE authored Oct 13, 2024
2 parents 02247b4 + 0e01363 commit 3bcee65
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions tests/Unit/DiscoveredFilesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

namespace BrianHenryIE\Strauss\Tests\Unit;

use BrianHenryIE\Strauss\File;
use BrianHenryIE\Strauss\TestCase;
use BrianHenryIE\Strauss\DiscoveredFiles;
use Mockery;

/**
* Class DiscoveredFilesTest.
*
* @coversDefaultClass \BrianHenryIE\Strauss\DiscoveredFiles
*
* @package BrianHenryIE\Strauss\Tests\Unit
*/
class DiscoveredFilesTest extends TestCase
{
/**
* Tests that a file can be added and gotten.
*
* @return void
*
* @author NikolayStrikhar
*/
public function testFileCanBeAddedAndGotten()
{
// Arrange.

$discovered_files = new DiscoveredFiles();

$file = Mockery::mock(File::class);
$file->shouldReceive('getTargetRelativePath')->andReturn('path/to/file1.php');

// Act.

$discovered_files->add($file);

// Assert.

$this->assertEquals(
['path/to/file1.php' => $file],
$discovered_files->getFiles()
);
}

/**
* Tests that multiple files with different paths can be added and gotten.
*
* @return void
*
* @author NikolayStrikhar
*/
public function testFileMultipleFilesWithDifferentPathsCanBeAddedAndGotten()
{
// Arrange.

$discovered_files = new DiscoveredFiles();

$file1 = Mockery::mock(File::class);
$file1->shouldReceive('getTargetRelativePath')->andReturn('path/to/file1.php');

$file2 = Mockery::mock(File::class);
$file2->shouldReceive('getTargetRelativePath')->andReturn('path/to/file2.php');

// Act.

$discovered_files->add($file1);
$discovered_files->add($file2);

// Assert.

$this->assertEquals(
[
'path/to/file1.php' => $file1,
'path/to/file2.php' => $file2,
],
$discovered_files->getFiles()
);
}

/**
* Tests that files are overwritten when they have the same path.
*
* @return void
*
* @author NikolayStrikhar
*/
public function testFilesWithSamePathsAreOverwritten()
{
// Arrange.

$discovered_files = new DiscoveredFiles();

$file1 = Mockery::mock(File::class);
$file1->shouldReceive('getTargetRelativePath')->andReturn('path/to/file1.php');

$file2 = Mockery::mock(File::class);
$file2->shouldReceive('getTargetRelativePath')->andReturn('path/to/file1.php');

// Act.

$discovered_files->add($file1);
$discovered_files->add($file2); // This should overwrite file 1.

// Assert.

$this->assertEquals(
['path/to/file1.php' => $file2],
$discovered_files->getFiles()
);
}
}

0 comments on commit 3bcee65

Please sign in to comment.