Debian Codegraph @

tests/phpunit/unit/includes/libs/StaticArrayWriterTest.php

raw symbols SCIP
1 <?php
2 /**
3 * Copyright (C) 2018 Kunal Mehta <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */
20
21 namespace Wikimedia\Tests;
22
23 use PHPUnit\Framework\TestCase;
24 use Wikimedia\StaticArrayWriter;
25
26 /**
27 * @covers \Wikimedia\StaticArrayWriter
28 */
29 class StaticArrayWriterTest extends TestCase {
30 public function testCreate() {
31 $data = [
32 'foo' => 'bar',
33 'baz' => 'rawr',
34 "they're" => '"quoted properly"',
35 'nested' => [ 'elements', 'work' ],
36 'intlike' => [ '050' => true, '101' => true, '221B' => true ],
37 'and' => [ 'these' => 'do too' ],
38 ];
39 $writer = new StaticArrayWriter();
40 $actual = $writer->create( $data, "Header\nWith\nNewlines" );
41 $expected = <<<PHP
42 <?php
43 // Header
44 // With
45 // Newlines
46 return [
47 'foo' => 'bar',
48 'baz' => 'rawr',
49 'they\'re' => '"quoted properly"',
50 'nested' => [
51 'elements',
52 'work',
53 ],
54 'intlike' => [
55 '050' => true,
56 101 => true,
57 '221B' => true,
58 ],
59 'and' => [
60 'these' => 'do too',
61 ],
62 ];
63
64 PHP;
65 $this->assertSame( $expected, $actual );
66 }
67
68 public function testWriteClass() {
69 $data = [
70 'foo' => 'bar',
71 'baz' => 'rawr',
72 ];
73 $writer = new StaticArrayWriter();
74 $actual = $writer->writeClass( $data, [
75 'header' => "Header\nWith\nNewlines",
76 'namespace' => 'Example\\Foo',
77 'class' => 'Bar',
78 'const' => 'THING',
79 ] );
80 $expected = <<<PHP
81 <?php
82 // Header
83 // With
84 // Newlines
85
86 namespace Example\Foo;
87
88 class Bar {
89 public const THING = [
90 'foo' => 'bar',
91 'baz' => 'rawr',
92 ];
93 }
94
95 PHP;
96 $this->assertSame( $expected, $actual );
97 }
98 }