PHP code example of jasonmccreary / expect
1. Go to this page and download the library: Download jasonmccreary/expect 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/ */
jasonmccreary / expect example snippets
// equality
expect(1)->toEqual('1');
expect(2)->toBe(2);
// comparison
expect(5)->toBeLessThan(7);
expect(5)->toBeLessThanOrEqualTo(5);
expect(5)->toBeGreaterThan(4);
expect(5)->toBeGreaterThanOrEqualTo(5);
// true / false / null
expect(true)->toBeTrue();
expect('1')->toBeTruthy();
expect(false)->toBeFalse();
expect('0')->toBeFalsy();
expect(null)->toBeNull();
// strings
expect('string')->toContain('in');
expect('string')->toStartWith('str');
expect('string')->toEndWith('ing');
expect('string')->toHaveLength(6);
expect('string')->toMatchPattern('/string/');
expect('string')->toMatchFormat('%s');
// arrays
expect(['a', 'b', 'c'])->toHaveCount(3);
expect(['a', 'b', 'c'])->toContain('a');
expect(['key' => 'value'])->toHaveKey('key');
// types
expect(1)->toBeType('int');
expect(new Example())->toBeInstanceOf(Example::class);
expect('{"key": "value"}')->toBeJson();
expect('<key>value</key>')->toBeXml();
// files
expect('file.txt')->toExist();
// negation
expect(1)->not()->toEqual(2);
expect(true)->not()->toBeFalse();
expect($value)->not()->toBeNull();