TomlBuilderInvalidTest.php 3.79 KB
Newer Older
victorpuertas's avatar
victorpuertas committed
1
2
3
4
5
6
7
8
9
10
<?php

/*
 * This file is part of the Yosymfony\Toml package.
 *
 * (c) YoSymfony <http://github.com/yosymfony>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
Yo! Symfony's avatar
Yo! Symfony committed
11
12

namespace Yosymfony\Toml\tests;
victorpuertas's avatar
victorpuertas committed
13

14
use PHPUnit\Framework\TestCase;
victorpuertas's avatar
victorpuertas committed
15
16
use Yosymfony\Toml\TomlBuilder;

17
class TomlBuilderInvalidTest extends TestCase
victorpuertas's avatar
victorpuertas committed
18
19
{
    /**
yosymfony's avatar
yosymfony committed
20
     * @expectedException Yosymfony\Toml\Exception\DumpException
victorpuertas's avatar
victorpuertas committed
21
22
23
     */
    public function testArrayMixedTypesArraysAndInts()
    {
Yo! Symfony's avatar
Yo! Symfony committed
24
25
        $tb = new TomlBuilder();

yosymfony's avatar
yosymfony committed
26
        $tb->addValue('arrays-and-ints', array(1, array('Arrays are not integers.')))
27
            ->getTomlString();
victorpuertas's avatar
victorpuertas committed
28
    }
Yo! Symfony's avatar
Yo! Symfony committed
29

victorpuertas's avatar
victorpuertas committed
30
    /**
yosymfony's avatar
yosymfony committed
31
     * @expectedException Yosymfony\Toml\Exception\DumpException
victorpuertas's avatar
victorpuertas committed
32
33
34
     */
    public function testArrayMixedTypesIntsAndFloats()
    {
Yo! Symfony's avatar
Yo! Symfony committed
35
        $tb = new TomlBuilder();
yosymfony's avatar
yosymfony committed
36
        $tb->addValue('arrays-and-ints', array(1, 1.0))
37
            ->getTomlString();
victorpuertas's avatar
victorpuertas committed
38
    }
Yo! Symfony's avatar
Yo! Symfony committed
39

victorpuertas's avatar
victorpuertas committed
40
    /**
yosymfony's avatar
yosymfony committed
41
     * @expectedException Yosymfony\Toml\Exception\DumpException
victorpuertas's avatar
victorpuertas committed
42
43
44
     */
    public function testArrayMixedTypesStringsAndInts()
    {
Yo! Symfony's avatar
Yo! Symfony committed
45
        $tb = new TomlBuilder();
yosymfony's avatar
yosymfony committed
46
        $tb->addValue('arrays-and-ints', array('hi', 42))
47
            ->getTomlString();
victorpuertas's avatar
victorpuertas committed
48
    }
Yo! Symfony's avatar
Yo! Symfony committed
49

victorpuertas's avatar
victorpuertas committed
50
    /**
yosymfony's avatar
yosymfony committed
51
     * @expectedException Yosymfony\Toml\Exception\DumpException
victorpuertas's avatar
victorpuertas committed
52
     */
53
    public function testDuplicateTable()
victorpuertas's avatar
victorpuertas committed
54
55
    {
        $tb = new TomlBuilder();
yosymfony's avatar
yosymfony committed
56
        $tb->addTable('a')
57
58
            ->addTable('a')
            ->getTomlString();
victorpuertas's avatar
victorpuertas committed
59
    }
Yo! Symfony's avatar
Yo! Symfony committed
60

victorpuertas's avatar
victorpuertas committed
61
    /**
yosymfony's avatar
yosymfony committed
62
     * @expectedException Yosymfony\Toml\Exception\DumpException
victorpuertas's avatar
victorpuertas committed
63
     */
64
    public function testDuplicateKeyTable()
victorpuertas's avatar
victorpuertas committed
65
66
    {
        $tb = new TomlBuilder();
yosymfony's avatar
yosymfony committed
67
        $tb->addTable('fruit')
68
69
70
            ->addValue('type', 'apple')
            ->addTable('fruit.type')
            ->getTomlString();
victorpuertas's avatar
victorpuertas committed
71
    }
Yo! Symfony's avatar
Yo! Symfony committed
72

victorpuertas's avatar
victorpuertas committed
73
    /**
yosymfony's avatar
yosymfony committed
74
     * @expectedException Yosymfony\Toml\Exception\DumpException
victorpuertas's avatar
victorpuertas committed
75
76
77
78
     */
    public function testDuplicateKeys()
    {
        $tb = new TomlBuilder();
yosymfony's avatar
yosymfony committed
79
        $tb->addValue('dupe', false)
80
81
            ->addValue('dupe', true)
            ->getTomlString();
victorpuertas's avatar
victorpuertas committed
82
    }
Yo! Symfony's avatar
Yo! Symfony committed
83

victorpuertas's avatar
victorpuertas committed
84
    /**
yosymfony's avatar
yosymfony committed
85
     * @expectedException Yosymfony\Toml\Exception\DumpException
victorpuertas's avatar
victorpuertas committed
86
     */
87
    public function testEmptyTable()
victorpuertas's avatar
victorpuertas committed
88
89
    {
        $tb = new TomlBuilder();
yosymfony's avatar
yosymfony committed
90
        $tb->addTable('')
91
            ->getTomlString();
victorpuertas's avatar
victorpuertas committed
92
    }
Yo! Symfony's avatar
Yo! Symfony committed
93

victorpuertas's avatar
victorpuertas committed
94
    /**
yosymfony's avatar
yosymfony committed
95
     * @expectedException Yosymfony\Toml\Exception\DumpException
victorpuertas's avatar
victorpuertas committed
96
97
98
99
     */
    public function testEmptyImplicitKeygroup()
    {
        $tb = new TomlBuilder();
yosymfony's avatar
yosymfony committed
100
        $tb->addTable('naughty..naughty')
101
            ->getTomlString();
victorpuertas's avatar
victorpuertas committed
102
    }
Yo! Symfony's avatar
Yo! Symfony committed
103

104
    /**
yosymfony's avatar
yosymfony committed
105
     * @expectedException Yosymfony\Toml\Exception\DumpException
106
107
108
109
     */
    public function testInvalidKey()
    {
        $tb = new TomlBuilder();
yosymfony's avatar
yosymfony committed
110
        $tb->addValue('value#1', '2')
111
112
113
            ->getTomlString();
    }

victorpuertas's avatar
victorpuertas committed
114
    /**
yosymfony's avatar
yosymfony committed
115
     * @expectedException Yosymfony\Toml\Exception\DumpException
victorpuertas's avatar
victorpuertas committed
116
117
118
119
     */
    public function testNullValue()
    {
        $tb = new TomlBuilder();
yosymfony's avatar
yosymfony committed
120
        $tb->addValue('theNull', null)
121
            ->getTomlString();
victorpuertas's avatar
victorpuertas committed
122
    }
Yo! Symfony's avatar
Yo! Symfony committed
123

yosymfony's avatar
yosymfony committed
124
    /**
yosymfony's avatar
yosymfony committed
125
     * @expectedException Yosymfony\Toml\Exception\DumpException
yosymfony's avatar
yosymfony committed
126
127
128
129
     */
    public function testTableArrayImplicit()
    {
        $tb = new TomlBuilder();
yosymfony's avatar
yosymfony committed
130
        $tb->addArrayTables('albums.songs')
yosymfony's avatar
yosymfony committed
131
                ->addValue('name', 'Glory Days')
132
            ->addArrayTables('albums')
yosymfony's avatar
yosymfony committed
133
134
135
                ->addValue('name', 'Born in the USA')
            ->getTomlString();
    }
Yo! Symfony's avatar
Yo! Symfony committed
136

yosymfony's avatar
yosymfony committed
137
    /**
yosymfony's avatar
yosymfony committed
138
     * @expectedException Yosymfony\Toml\Exception\DumpException
yosymfony's avatar
yosymfony committed
139
140
141
142
     */
    public function testTableArrayWithSomeNameOfTable()
    {
        $tb = new TomlBuilder();
yosymfony's avatar
yosymfony committed
143
        $tb->addArrayTables('fruit')
yosymfony's avatar
yosymfony committed
144
                ->addValue('name', 'apple')
145
            ->addArrayTables('fruit.variety')
yosymfony's avatar
yosymfony committed
146
147
148
149
150
                ->addValue('name', 'red delicious')
            ->addTable('fruit.variety')
                ->addValue('name', 'granny smith')
            ->getTomlString();
    }
Yo! Symfony's avatar
Yo! Symfony committed
151
}