Overview

Namespaces

  • Composer
    • Autoload
  • Guzzle
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
        • Header
      • QueryAggregator
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Mock
    • Stream
  • Mockery
    • Adapter
      • Phpunit
    • CountValidator
    • Exception
    • Generator
      • StringManipulation
        • Pass
    • Loader
    • Matcher
  • None
  • Omnipay
    • Common
      • Exception
      • Message
    • Dummy
      • Message
    • Fatzebra
      • Message
  • PHP
  • Symfony
    • Component
      • EventDispatcher
        • Debug
        • DependencyInjection
        • Tests
          • Debug
          • DependencyInjection
      • HttpFoundation
        • File
          • Exception
          • MimeType
        • Session
          • Attribute
          • Flash
          • Storage
            • Handler
            • Proxy
        • Tests
          • File
            • MimeType
          • Session
            • Attribute
            • Flash
            • Storage
              • Handler
              • Proxy
      • Yaml
        • Exception
        • Tests

Classes

  • Symfony\Component\Yaml\Tests\A
  • Symfony\Component\Yaml\Tests\B
  • Symfony\Component\Yaml\Tests\DumperTest
  • Symfony\Component\Yaml\Tests\InlineTest
  • Symfony\Component\Yaml\Tests\ParseExceptionTest
  • Symfony\Component\Yaml\Tests\ParserTest
  • Symfony\Component\Yaml\Tests\YamlTest
  • Overview
  • Namespace
  • Function
  • Tree
  1: <?php
  2: 
  3: /*
  4:  * This file is part of the Symfony package.
  5:  *
  6:  * (c) Fabien Potencier <fabien@symfony.com>
  7:  *
  8:  * For the full copyright and license information, please view the LICENSE
  9:  * file that was distributed with this source code.
 10:  */
 11: 
 12: namespace Symfony\Component\Yaml\Tests;
 13: 
 14: use Symfony\Component\Yaml\Inline;
 15: 
 16: class InlineTest extends \PHPUnit_Framework_TestCase
 17: {
 18:     /**
 19:      * @dataProvider getTestsForParse
 20:      */
 21:     public function testParse($yaml, $value)
 22:     {
 23:         $this->assertSame($value, Inline::parse($yaml), sprintf('::parse() converts an inline YAML to a PHP structure (%s)', $yaml));
 24:     }
 25: 
 26:     /**
 27:      * @dataProvider getTestsForParseWithMapObjects
 28:      */
 29:     public function testParseWithMapObjects($yaml, $value)
 30:     {
 31:         $actual = Inline::parse($yaml, false, false, true);
 32: 
 33:         $this->assertSame(serialize($value), serialize($actual));
 34:     }
 35: 
 36:     /**
 37:      * @dataProvider getTestsForDump
 38:      */
 39:     public function testDump($yaml, $value)
 40:     {
 41:         $this->assertEquals($yaml, Inline::dump($value), sprintf('::dump() converts a PHP structure to an inline YAML (%s)', $yaml));
 42: 
 43:         $this->assertSame($value, Inline::parse(Inline::dump($value)), 'check consistency');
 44:     }
 45: 
 46:     public function testDumpNumericValueWithLocale()
 47:     {
 48:         $locale = setlocale(LC_NUMERIC, 0);
 49:         if (false === $locale) {
 50:             $this->markTestSkipped('Your platform does not support locales.');
 51:         }
 52: 
 53:         $required_locales = array('fr_FR.UTF-8', 'fr_FR.UTF8', 'fr_FR.utf-8', 'fr_FR.utf8', 'French_France.1252');
 54:         if (false === setlocale(LC_ALL, $required_locales)) {
 55:             $this->markTestSkipped('Could not set any of required locales: '.implode(", ", $required_locales));
 56:         }
 57: 
 58:         $this->assertEquals('1.2', Inline::dump(1.2));
 59:         $this->assertContains('fr', strtolower(setlocale(LC_NUMERIC, 0)));
 60: 
 61:         setlocale(LC_ALL, $locale);
 62:     }
 63: 
 64:     public function testHashStringsResemblingExponentialNumericsShouldNotBeChangedToINF()
 65:     {
 66:         $value = '686e444';
 67: 
 68:         $this->assertSame($value, Inline::parse(Inline::dump($value)));
 69:     }
 70: 
 71:     /**
 72:      * @expectedException \Symfony\Component\Yaml\Exception\ParseException
 73:      */
 74:     public function testParseScalarWithIncorrectlyQuotedStringShouldThrowException()
 75:     {
 76:         $value = "'don't do somthin' like that'";
 77:         Inline::parse($value);
 78:     }
 79: 
 80:     /**
 81:      * @expectedException \Symfony\Component\Yaml\Exception\ParseException
 82:      */
 83:     public function testParseScalarWithIncorrectlyDoubleQuotedStringShouldThrowException()
 84:     {
 85:         $value = '"don"t do somthin" like that"';
 86:         Inline::parse($value);
 87:     }
 88: 
 89:     /**
 90:      * @expectedException \Symfony\Component\Yaml\Exception\ParseException
 91:      */
 92:     public function testParseInvalidMappingKeyShouldThrowException()
 93:     {
 94:         $value = '{ "foo " bar": "bar" }';
 95:         Inline::parse($value);
 96:     }
 97: 
 98:     /**
 99:      * @expectedException \Symfony\Component\Yaml\Exception\ParseException
100:      */
101:     public function testParseInvalidMappingShouldThrowException()
102:     {
103:         Inline::parse('[foo] bar');
104:     }
105: 
106:     /**
107:      * @expectedException \Symfony\Component\Yaml\Exception\ParseException
108:      */
109:     public function testParseInvalidSequenceShouldThrowException()
110:     {
111:         Inline::parse('{ foo: bar } bar');
112:     }
113: 
114:     public function testParseScalarWithCorrectlyQuotedStringShouldReturnString()
115:     {
116:         $value = "'don''t do somthin'' like that'";
117:         $expect = "don't do somthin' like that";
118: 
119:         $this->assertSame($expect, Inline::parseScalar($value));
120:     }
121: 
122:     /**
123:      * @dataProvider getDataForParseReferences
124:      */
125:     public function testParseReferences($yaml, $expected)
126:     {
127:         $this->assertSame($expected, Inline::parse($yaml, false, false, false, array('var' => 'var-value')));
128:     }
129: 
130:     public function getDataForParseReferences()
131:     {
132:         return array(
133:             'scalar' => array('*var', 'var-value'),
134:             'list' => array('[ *var ]', array('var-value')),
135:             'list-in-list' => array('[[ *var ]]', array(array('var-value'))),
136:             'map-in-list' => array('[ { key: *var } ]', array(array('key' => 'var-value'))),
137:             'embedded-mapping-in-list' => array('[ key: *var ]', array(array('key' => 'var-value'))),
138:             'map' => array('{ key: *var }', array('key' => 'var-value')),
139:             'list-in-map' => array('{ key: [*var] }', array('key' => array('var-value'))),
140:             'map-in-map' => array('{ foo: { bar: *var } }', array('foo' => array('bar' => 'var-value'))),
141:         );
142:     }
143: 
144:     public function testParseMapReferenceInSequence()
145:     {
146:         $foo = array(
147:             'a' => 'Steve',
148:             'b' => 'Clark',
149:             'c' => 'Brian',
150:         );
151:         $this->assertSame(array($foo), Inline::parse('[*foo]', false, false, false, array('foo' => $foo)));
152:     }
153: 
154:     /**
155:      * @expectedException \Symfony\Component\Yaml\Exception\ParseException
156:      * @expectedExceptionMessage A reference must contain at least one character.
157:      */
158:     public function testParseUnquotedAsterisk()
159:     {
160:         Inline::parse('{ foo: * }');
161:     }
162: 
163:     /**
164:      * @expectedException \Symfony\Component\Yaml\Exception\ParseException
165:      * @expectedExceptionMessage A reference must contain at least one character.
166:      */
167:     public function testParseUnquotedAsteriskFollowedByAComment()
168:     {
169:         Inline::parse('{ foo: * #foo }');
170:     }
171: 
172:     public function getTestsForParse()
173:     {
174:         return array(
175:             array('', ''),
176:             array('null', null),
177:             array('false', false),
178:             array('true', true),
179:             array('12', 12),
180:             array('-12', -12),
181:             array('"quoted string"', 'quoted string'),
182:             array("'quoted string'", 'quoted string'),
183:             array('12.30e+02', 12.30e+02),
184:             array('0x4D2', 0x4D2),
185:             array('02333', 02333),
186:             array('.Inf', -log(0)),
187:             array('-.Inf', log(0)),
188:             array("'686e444'", '686e444'),
189:             array('686e444', 646e444),
190:             array('123456789123456789123456789123456789', '123456789123456789123456789123456789'),
191:             array('"foo\r\nbar"', "foo\r\nbar"),
192:             array("'foo#bar'", 'foo#bar'),
193:             array("'foo # bar'", 'foo # bar'),
194:             array("'#cfcfcf'", '#cfcfcf'),
195:             array('::form_base.html.twig', '::form_base.html.twig'),
196: 
197:             // Pre-YAML-1.2 booleans
198:             array("'y'", 'y'),
199:             array("'n'", 'n'),
200:             array("'yes'", 'yes'),
201:             array("'no'", 'no'),
202:             array("'on'", 'on'),
203:             array("'off'", 'off'),
204: 
205:             array('2007-10-30', mktime(0, 0, 0, 10, 30, 2007)),
206:             array('2007-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 2007)),
207:             array('2007-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 2007)),
208:             array('1960-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 1960)),
209:             array('1730-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 1730)),
210: 
211:             array('"a \\"string\\" with \'quoted strings inside\'"', 'a "string" with \'quoted strings inside\''),
212:             array("'a \"string\" with ''quoted strings inside'''", 'a "string" with \'quoted strings inside\''),
213: 
214:             // sequences
215:             // urls are no key value mapping. see #3609. Valid yaml "key: value" mappings require a space after the colon
216:             array('[foo, http://urls.are/no/mappings, false, null, 12]', array('foo', 'http://urls.are/no/mappings', false, null, 12)),
217:             array('[  foo  ,   bar , false  ,  null     ,  12  ]', array('foo', 'bar', false, null, 12)),
218:             array('[\'foo,bar\', \'foo bar\']', array('foo,bar', 'foo bar')),
219: 
220:             // mappings
221:             array('{foo:bar,bar:foo,false:false,null:null,integer:12}', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
222:             array('{ foo  : bar, bar : foo,  false  :   false,  null  :   null,  integer :  12  }', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
223:             array('{foo: \'bar\', bar: \'foo: bar\'}', array('foo' => 'bar', 'bar' => 'foo: bar')),
224:             array('{\'foo\': \'bar\', "bar": \'foo: bar\'}', array('foo' => 'bar', 'bar' => 'foo: bar')),
225:             array('{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}', array('foo\'' => 'bar', "bar\"" => 'foo: bar')),
226:             array('{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}', array('foo: ' => 'bar', "bar: " => 'foo: bar')),
227: 
228:             // nested sequences and mappings
229:             array('[foo, [bar, foo]]', array('foo', array('bar', 'foo'))),
230:             array('[foo, {bar: foo}]', array('foo', array('bar' => 'foo'))),
231:             array('{ foo: {bar: foo} }', array('foo' => array('bar' => 'foo'))),
232:             array('{ foo: [bar, foo] }', array('foo' => array('bar', 'foo'))),
233: 
234:             array('[  foo, [  bar, foo  ]  ]', array('foo', array('bar', 'foo'))),
235: 
236:             array('[{ foo: {bar: foo} }]', array(array('foo' => array('bar' => 'foo')))),
237: 
238:             array('[foo, [bar, [foo, [bar, foo]], foo]]', array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo'))),
239: 
240:             array('[foo, {bar: foo, foo: [foo, {bar: foo}]}, [foo, {bar: foo}]]', array('foo', array('bar' => 'foo', 'foo' => array('foo', array('bar' => 'foo'))), array('foo', array('bar' => 'foo')))),
241: 
242:             array('[foo, bar: { foo: bar }]', array('foo', '1' => array('bar' => array('foo' => 'bar')))),
243:             array('[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']', array('foo', '@foo.baz', array('%foo%' => 'foo is %foo%', 'bar' => '%foo%'), true, '@service_container')),
244:         );
245:     }
246: 
247:     public function getTestsForParseWithMapObjects()
248:     {
249:         return array(
250:             array('', ''),
251:             array('null', null),
252:             array('false', false),
253:             array('true', true),
254:             array('12', 12),
255:             array('-12', -12),
256:             array('"quoted string"', 'quoted string'),
257:             array("'quoted string'", 'quoted string'),
258:             array('12.30e+02', 12.30e+02),
259:             array('0x4D2', 0x4D2),
260:             array('02333', 02333),
261:             array('.Inf', -log(0)),
262:             array('-.Inf', log(0)),
263:             array("'686e444'", '686e444'),
264:             array('686e444', 646e444),
265:             array('123456789123456789123456789123456789', '123456789123456789123456789123456789'),
266:             array('"foo\r\nbar"', "foo\r\nbar"),
267:             array("'foo#bar'", 'foo#bar'),
268:             array("'foo # bar'", 'foo # bar'),
269:             array("'#cfcfcf'", '#cfcfcf'),
270:             array('::form_base.html.twig', '::form_base.html.twig'),
271: 
272:             array('2007-10-30', mktime(0, 0, 0, 10, 30, 2007)),
273:             array('2007-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 2007)),
274:             array('2007-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 2007)),
275:             array('1960-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 1960)),
276:             array('1730-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 1730)),
277: 
278:             array('"a \\"string\\" with \'quoted strings inside\'"', 'a "string" with \'quoted strings inside\''),
279:             array("'a \"string\" with ''quoted strings inside'''", 'a "string" with \'quoted strings inside\''),
280: 
281:             // sequences
282:             // urls are no key value mapping. see #3609. Valid yaml "key: value" mappings require a space after the colon
283:             array('[foo, http://urls.are/no/mappings, false, null, 12]', array('foo', 'http://urls.are/no/mappings', false, null, 12)),
284:             array('[  foo  ,   bar , false  ,  null     ,  12  ]', array('foo', 'bar', false, null, 12)),
285:             array('[\'foo,bar\', \'foo bar\']', array('foo,bar', 'foo bar')),
286: 
287:             // mappings
288:             array('{foo:bar,bar:foo,false:false,null:null,integer:12}', (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
289:             array('{ foo  : bar, bar : foo,  false  :   false,  null  :   null,  integer :  12  }', (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
290:             array('{foo: \'bar\', bar: \'foo: bar\'}', (object) array('foo' => 'bar', 'bar' => 'foo: bar')),
291:             array('{\'foo\': \'bar\', "bar": \'foo: bar\'}', (object) array('foo' => 'bar', 'bar' => 'foo: bar')),
292:             array('{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}', (object) array('foo\'' => 'bar', "bar\"" => 'foo: bar')),
293:             array('{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}', (object) array('foo: ' => 'bar', "bar: " => 'foo: bar')),
294: 
295:             // nested sequences and mappings
296:             array('[foo, [bar, foo]]', array('foo', array('bar', 'foo'))),
297:             array('[foo, {bar: foo}]', array('foo', (object) array('bar' => 'foo'))),
298:             array('{ foo: {bar: foo} }', (object) array('foo' => (object) array('bar' => 'foo'))),
299:             array('{ foo: [bar, foo] }', (object) array('foo' => array('bar', 'foo'))),
300: 
301:             array('[  foo, [  bar, foo  ]  ]', array('foo', array('bar', 'foo'))),
302: 
303:             array('[{ foo: {bar: foo} }]', array((object) array('foo' => (object) array('bar' => 'foo')))),
304: 
305:             array('[foo, [bar, [foo, [bar, foo]], foo]]', array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo'))),
306: 
307:             array('[foo, {bar: foo, foo: [foo, {bar: foo}]}, [foo, {bar: foo}]]', array('foo', (object) array('bar' => 'foo', 'foo' => array('foo', (object) array('bar' => 'foo'))), array('foo', (object) array('bar' => 'foo')))),
308: 
309:             array('[foo, bar: { foo: bar }]', array('foo', '1' => (object) array('bar' => (object) array('foo' => 'bar')))),
310:             array('[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']', array('foo', '@foo.baz', (object) array('%foo%' => 'foo is %foo%', 'bar' => '%foo%'), true, '@service_container')),
311: 
312:             array('{}', new \stdClass()),
313:             array('{ foo  : bar, bar : {}  }', (object) array('foo' => 'bar', 'bar' => new \stdClass())),
314:             array('{ foo  : [], bar : {}  }', (object) array('foo' => array(), 'bar' => new \stdClass())),
315:             array('{foo: \'bar\', bar: {} }', (object) array('foo' => 'bar', 'bar' => new \stdClass())),
316:             array('{\'foo\': \'bar\', "bar": {}}', (object) array('foo' => 'bar', 'bar' => new \stdClass())),
317:             array('{\'foo\': \'bar\', "bar": \'{}\'}', (object) array('foo' => 'bar', 'bar' => '{}')),
318: 
319:             array('[foo, [{}, {}]]', array('foo', array(new \stdClass(), new \stdClass()))),
320:             array('[foo, [[], {}]]', array('foo', array(array(), new \stdClass()))),
321:             array('[foo, [[{}, {}], {}]]', array('foo', array(array(new \stdClass(), new \stdClass()), new \stdClass()))),
322:             array('[foo, {bar: {}}]', array('foo', '1' => (object) array('bar' => new \stdClass()))),
323:         );
324:     }
325: 
326:     public function getTestsForDump()
327:     {
328:         return array(
329:             array('null', null),
330:             array('false', false),
331:             array('true', true),
332:             array('12', 12),
333:             array("'quoted string'", 'quoted string'),
334:             array('!!float 1230', 12.30e+02),
335:             array('1234', 0x4D2),
336:             array('1243', 02333),
337:             array('.Inf', -log(0)),
338:             array('-.Inf', log(0)),
339:             array("'686e444'", '686e444'),
340:             array('"foo\r\nbar"', "foo\r\nbar"),
341:             array("'foo#bar'", 'foo#bar'),
342:             array("'foo # bar'", 'foo # bar'),
343:             array("'#cfcfcf'", '#cfcfcf'),
344: 
345:             array("'a \"string\" with ''quoted strings inside'''", 'a "string" with \'quoted strings inside\''),
346: 
347:             array("'-dash'", '-dash'),
348:             array("'-'", '-'),
349: 
350:             // Pre-YAML-1.2 booleans
351:             array("'y'", 'y'),
352:             array("'n'", 'n'),
353:             array("'yes'", 'yes'),
354:             array("'no'", 'no'),
355:             array("'on'", 'on'),
356:             array("'off'", 'off'),
357: 
358:             // sequences
359:             array('[foo, bar, false, null, 12]', array('foo', 'bar', false, null, 12)),
360:             array('[\'foo,bar\', \'foo bar\']', array('foo,bar', 'foo bar')),
361: 
362:             // mappings
363:             array('{ foo: bar, bar: foo, \'false\': false, \'null\': null, integer: 12 }', array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12)),
364:             array('{ foo: bar, bar: \'foo: bar\' }', array('foo' => 'bar', 'bar' => 'foo: bar')),
365: 
366:             // nested sequences and mappings
367:             array('[foo, [bar, foo]]', array('foo', array('bar', 'foo'))),
368: 
369:             array('[foo, [bar, [foo, [bar, foo]], foo]]', array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo'))),
370: 
371:             array('{ foo: { bar: foo } }', array('foo' => array('bar' => 'foo'))),
372: 
373:             array('[foo, { bar: foo }]', array('foo', array('bar' => 'foo'))),
374: 
375:             array('[foo, { bar: foo, foo: [foo, { bar: foo }] }, [foo, { bar: foo }]]', array('foo', array('bar' => 'foo', 'foo' => array('foo', array('bar' => 'foo'))), array('foo', array('bar' => 'foo')))),
376: 
377:             array('[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']', array('foo', '@foo.baz', array('%foo%' => 'foo is %foo%', 'bar' => '%foo%'), true, '@service_container')),
378:         );
379:     }
380: }
381: 
Omnipay Fat Zebra / Paystream Gateway Module API Documentation API documentation generated by ApiGen