Allows to match directory/file existance and basic file content match.
-
Add composer dependency
composer require --dev "ecomdev/phpspec-file-matcher"
-
Add extension to your PHPSpec configuration
extensions: - EcomDev\PHPSpec\FileMatcher\Extension
-
Directory existance:
shouldCreateDirectory($path)
shouldBeDirectory($path)
shouldHaveDirectory($path)
-
File existance:
shouldCreateFile($filePath)
shouldBeFile($filePath)
shouldHaveFile($filePath)
-
File content:
shouldCreateFileContent($filePath, $content)
shouldHaveFile($filePath, $content)
<?php
namespace spec\Example;
use PhpSpec\ObjectBehavior;
class FileSpec extends ObjectBehavior
{
function it_creates_a_file_on_save()
{
$this->save('file.txt', 'some_nice_content')
->shouldCreateFile('file.txt')
->shouldHaveFileContent('file.txt', 'some_nice_content');
}
}