ecomdev/phpspec-file-matcher

PHPSpec 扩展,增加文件匹配器

2.0.2 2016-09-15 09:47 UTC

This package is auto-updated.

Last update: 2024-08-27 21:08:27 UTC


README

允许匹配目录/文件的存在以及基本文件内容匹配。

安装

  1. 添加 composer 依赖

    composer require --dev "ecomdev/phpspec-file-matcher"
  2. 将扩展添加到您的 PHPSpec 配置

    extensions:
      EcomDev\PHPSpec\FileMatcher\Extension: ~

匹配器

  • 目录存在

    • shouldCreateDirectory($path)
    • shouldBeDirectory($path)
    • shouldHaveDirectory($path)
  • 文件存在

    • shouldCreateFile($filePath)
    • shouldBeFile($filePath)
    • shouldHaveFile($filePath)
  • 文件内容

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