/[A3C]/t/40-php.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /t/40-php.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 133 - (show annotations)
Fri May 30 20:04:23 2008 UTC (14 years, 4 months ago) by dpavlin
File MIME type: application/x-troff
File size: 1389 byte(s)
Added Parse::RecDescent PHP parser based on PHP::Include

PHP::Include puts new variables in current scope, while we
prefer to get single hash with all defined values.
1 #!/usr/bin/env perl
2 use warnings;
3 use strict;
4
5 =head1 DESCRIPTION
6
7 test PHP data parser
8
9 =cut
10
11 use Jifty::Test tests => 8;
12
13 use Data::Dump qw/dump/;
14
15 use_ok('A3C::PHP');
16
17 $A3C::PHP::debug = 1 if @ARGV;
18
19 ok( my $data = A3C::PHP->parse( << '__PHP_CONFIG__'
20 <?
21 $_foo = 42;
22 $_bar = "is bar";
23
24 $_baz = 'once';
25 $_baz = "twice";
26 ?>
27 __PHP_CONFIG__
28 ), 'parse');
29
30 diag dump( $data );
31 is_deeply( $data, { _foo => 42, _bar => "is bar", _baz => "twice" }, 'correct' );
32
33 sub php2data {
34 my ( $php_path, $expected ) = @_;
35 ok( my $data = A3C::PHP->parse_file( $php_path ), "parse_file( $php_path )");
36 diag "data = ",dump( $data );
37 is_deeply( $data, $expected, 'correct' );
38 }
39
40 SKIP: {
41 skip 'need function support', 1;
42 php2data( 'data/strix/etc/cms-qa/conf.php' );
43 }
44
45 php2data( 'data/strix/etc/new/conf.php' );
46
47 php2data( 't/test.php',
48 {
49 array1 => [123],
50 array2 => [123, 456, 789],
51 array3 => ["abc"],
52 array4 => ["abc", "def", "ghi"],
53 array5 => ["test", "NJ, the garden state"],
54 array6 => ["foo"],
55 hash1 => { a => 1 },
56 hash2 => { a => 1, b => 2, c => 3 },
57 hash3 => { 1 => "a", "123.45" => "moog", foo => "bar" },
58 hash4 => { abe => "Abraham Lincoln", larry => "Larry Wall" },
59 hash5 => { constant => "NJ and you, perfect together" },
60 hash6 => { foo => "bar" },
61 number1 => 123,
62 number2 => "123.45",
63 string1 => "McHenry, IL",
64 string2 => "Trenton, NJ",
65 }
66 );

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26