Exemplo n.º 1
0
         $expectation = new Expectation($example);
         $expectation->expect(1)->toBeAnExampleOf('a number');
         $messages = $expectation->message();
         expect($messages[0])->toBe("Expected 1 to be an example of 'a number'");
         expect($messages[1])->toBe("Expected 1 not to be an example of 'a number'");
     });
     it('supports overriding default', function () {
         $example = ['toHaveCustomMessage' => function () {
             $this->message = function () {
                 return ['regular message', 'inverted message'];
             };
             return false;
         }];
         $expectation = new Expectation($example);
         $expectation->expect()->toHaveCustomMessage();
         $messages = $expectation->message();
         expect($messages[0])->toBe('regular message');
         expect($messages[1])->toBe('inverted message');
     });
 });
 it('can be inverted', function () {
     $example = ['toPass' => function () {
         return true;
     }, 'toFail' => function () {
         return false;
     }];
     $do = new Expectation($example);
     expect($do->expect()->not->toPass())->toBe(false);
     expect($do->expect()->not->toFail())->toBe(true);
 });
 describe('pretty-prints', function () {
Exemplo n.º 2
0
<?php

use Physalis\Spec;
use Physalis\Expectation;
describe('toBeOfType', function () {
    $do;
    beforeEach(function () use(&$do) {
        global $coreMatchers;
        $do = new Expectation($coreMatchers);
    });
    it('knows about strings', function () use(&$do) {
        expect($do->expect('a string')->toBeOfType('string'))->toBe(true);
        $messages = $do->message();
        expect($messages[0])->toBe("Expected 'a string' to be of type <string>");
        expect($messages[1])->toBe("Expected 'a string' not to be of type <string>");
    });
    it('knows about integers', function () use(&$do) {
        expect($do->expect(123)->toBeOfType('integer'))->toBe(true);
        $messages = $do->message();
        expect($messages[0])->toBe("Expected 123 to be of type <integer>");
        expect($messages[1])->toBe("Expected 123 not to be of type <integer>");
    });
    it('knows about doubles', function () use(&$do) {
        expect($do->expect(4.56)->toBeOfType('double'))->toBe(true);
        $messages = $do->message();
        expect($messages[0])->toBe("Expected 4.56 to be of type <double>");
        expect($messages[1])->toBe("Expected 4.56 not to be of type <double>");
    });
    it('knows about arrays', function () use(&$do) {
        expect($do->expect([7, 8, 9])->toBeOfType('array'))->toBe(true);
        $messages = $do->message();