Add php protobuffer support for transition to GTFS-realtime
[busui.git] / lib / Protobuf-PHP / tests / Protobuf.spec.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
 
require_once __DIR__ . '/../library/DrSlump/Protobuf.php';
 
use DrSlump\Protobuf;
 
describe 'Protobuf'
 
    //before
        Protobuf::autoload();
    //end
 
    it 'should autoload classes'
        new Protobuf\Codec\Binary();
    end.
 
    describe 'codecs registry'
        it 'should get a default codec if none set'
            $codec = Protobuf::getCodec();
            $codec should be an instance of '\DrSlump\Protobuf\CodecInterface';
        end.
 
        it 'should return the passed codec instance'
            $passed = new Protobuf\Codec\Binary();
            $getted = Protobuf::getCodec($passed);
            $getted should be $passed
        end.
 
        it. 'should register a new codec'
            $setted = new Protobuf\Codec\Binary();
            Protobuf::registerCodec('test', $setted);
            $getted = Protobuf::getCodec('test');
            $getted should be $setted
        end.
 
        it 'should register a new default codec'
            $setted = new Protobuf\Codec\Binary();
            Protobuf::setDefaultCodec($setted);
            Protobuf::getCodec() should be $setted
        end.
 
        # throws DrSlump\Protobuf\Exception
        it. 'should unregister a codec'
            $setted = new Protobuf\Codec\Binary();
            Protobuf::registerCodec('test', $setted);
            $result = Protobuf::unregisterCodec('test');
            $result should be true;
            // If not set throws an exception
            Protobuf::getCodec('test');
        end.
 
        it. 'should unregister the default codec'
            $result = Protobuf::unregisterCodec('default');
            $result should be true;
            // Ensure a new default is given
            $getted = Protobuf::getCodec();
            $getted should be instanceof 'DrSlump\Protobuf\Codec\Binary'
        end.
    end;
end;