PHP code example of ralphjsmit / pest-plugin-filesystem

1. Go to this page and download the library: Download ralphjsmit/pest-plugin-filesystem library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ralphjsmit / pest-plugin-filesystem example snippets


file_put_contents(__DIR__ . '/tmp/fileA.php', 'I\'m a test file!');
file_put_contents(__DIR__ . '/tmp/fileB.php', 'I\'m a second test file!');

expect(__DIR__ . '/tmp/fileA.php')->toHaveContents('I\'m a test file!');
expect(__DIR__ . '/tmp/fileB.php')->not->toHaveContents('I\'m a test file!');

expect(__DIR__ . '/tmp/fileA.php')->toExist();

expect(__DIR__ . '/tmp/fileA.php')->toHaveNamespace('App\Models');

file_put_contents(__DIR__ . '/tmp/fileA.php', 'I\'m a test file!');

expect(__DIR__ . '/tmp/fileA.php')
    ->contents->toBe('I\'m a test file!')
    ->toContain('test file')
    ->not->toContain('Hello world');

use function RalphJSmit\PestPluginFilesystem\rm;

rm(__DIR__ . '/tmp'); // Make sure that this file or directory doesn't exist

file_put_contents(__DIR__ . '/tmp/fileA.php', 'I\'m a test file!');
file_put_contents(__DIR__ . '/tmp/fileB.php', 'I\'m a second test file!');

// Other code

use function RalphJSmit\PestPluginFilesystem\rmdir_recursive;

rmdir_recursive(__DIR__ . '/tmp'); // Recursively remove this directory

use function RalphJSmit\PestPluginFilesystem\contents;

expect(
    contents(__DIR__ . '/tmp/fileA.php')
)->toBe(
    contents(__DIR__ . '/tmp/fileB.php')
);

use function RalphJSmit\PestPluginFilesystem\expectFailedAssertion;

expectFailedAssertion();
expect(true)->toBe(false);

// This test will pass

// Somewhere
expect()->extend('toBeHello', function () {
    return $this->toBe('Hello there');
});

// In your test
use function RalphJSmit\PestPluginFilesystem\expectFailedAssertion;

expect('Hello there')->toBeHello(); // This will pass

expectFailedAssertion();
expect('Bye')->toBeHello(); // This will pass

expectFailedAssertion();
expect('Hello there')->toBeHello(); // This will fail