ecomdev/phpspec-file-matcher

PHPSpec extension that adds file matcher

2.0.2 2016-09-15 09:47 UTC

This package is auto-updated.

Last update: 2024-10-27 21:29:42 UTC


README

Allows to match directory/file existence and basic file content match.

Installation

  1. Add composer dependency

    composer require --dev "ecomdev/phpspec-file-matcher"
  2. Add extension to your PHPSpec configuration

    extensions:
      EcomDev\PHPSpec\FileMatcher\Extension: ~

Matchers

  • Directory existence:

    • shouldCreateDirectory($path)
    • shouldBeDirectory($path)
    • shouldHaveDirectory($path)
  • File existence:

    • shouldCreateFile($filePath)
    • shouldBeFile($filePath)
    • shouldHaveFile($filePath)
  • File content:

    • shouldCreateFileContent($filePath, $content)
    • shouldHaveFile($filePath, $content)

Example

<?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');
     }
}