Skip to content

Commit

Permalink
add visitor to remove second argument from stream_context_create func…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
endel committed Dec 29, 2014
1 parent 3fa47bb commit 3f1d21b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/php54.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ function visitors() {
new CallableTypehint,
new ObjectInstAccess,
new Traits,
new SessionHandling
new SessionHandling,
new StreamContext
];
}

Expand Down Expand Up @@ -54,3 +55,9 @@ function transform_session_handling($code) {
new SessionHandling,
]);
}

function transform_stream_context($code) {
return g\transform_with_visitors($code, [
new StreamContext,
]);
}
21 changes: 21 additions & 0 deletions src/php54/StreamContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace galapagos\php54;

class StreamContext extends \PHPParser_NodeVisitorAbstract {

public function enterNode(\PHPParser_Node $node) {

if ($node instanceof \PhpParser\Node\Expr\FuncCall &&
$node->name == "stream_context_create" &&
count($node->args) == 2)
{
array_pop($node->args);
return $node;
}
}

}



22 changes: 22 additions & 0 deletions tests/php54/StreamContextTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace galapagos\php54;

use galapagos\AbstractTestCase;

class StreamContextTest extends AbstractTestCase {
/** @dataProvider provideTests */
public function testTransform($name, $code, $expected) {
$this->assertSame(
$this->canonicalize($expected),
$this->canonicalize(transform_stream_context($code)),
$name
);
}

public function provideTests() {
return $this->getTests(__DIR__.'/stream_context', 'test');
}
}


11 changes: 11 additions & 0 deletions tests/php54/stream_context/basic.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Calling stream_context_create with more than 1 param.
-----
<?php

$ctx = stream_context_create($options);
$ctx = stream_context_create($options, $default);
-----
<?php

$ctx = stream_context_create($options);
$ctx = stream_context_create($options);

0 comments on commit 3f1d21b

Please sign in to comment.