PHP code example of petrknap / shorts

1. Go to this page and download the library: Download petrknap/shorts 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/ */

    

petrknap / shorts example snippets


interface ImageResizerException extends Throwable {}

final class ImageResizerCouldNotResizeImage extends PetrKnap\Shorts\Exception\CouldNotProcessData implements ImageResizerException {}

final class ImageResizer {
    public function resize(string $image) {
        throw new ImageResizerCouldNotResizeImage(__METHOD__, $image);
    }
}

final class StringablePrototype implements Stringable {
    public function __toString(): string {
        PetrKnap\Shorts\Exception\NotImplemented::throw(__METHOD__);
    }
}

final class ServiceWithRequirements {
    use PetrKnap\Shorts\HasRequirements;
    
    public function __construct() {
        self::checkRequirements(functions: ['

$pdo = new PDO('sqlite::memory:');
$pdo->exec('CREATE TABLE tigers (id INTEGER PRIMARY KEY, name VARCHAR)');
$pdo->prepare('INSERT INTO tigers (name) VALUES (?), (?), (?)')
    ->execute(['Roque', 'Jasper', 'Gopal']);

PetrKnap\Shorts\Testing\IlluminateDatabase::createCapsuleManager($pdo)
    ->bootEloquent();

class Tiger extends Illuminate\Database\Eloquent\Model {}

assert(Tiger::count() === 3);

final class ReadmeTest extends PHPUnit\Framework\TestCase implements PetrKnap\Shorts\PhpUnit\MarkdownFileTestInterface {
    use PetrKnap\Shorts\PhpUnit\MarkdownFileTestTrait;

    public static function getPathToMarkdownFile(): string {
        return __DIR__ . '/../README.md';
    }

    public static function getExpectedOutputsOfPhpExamples(): array {
        return [
            'some example' => 'has this output',
        ];
    }
}