Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Updating code to use namespaced Twig classes
Browse files Browse the repository at this point in the history
  • Loading branch information
emulienfou authored and OskarStark committed May 20, 2019
1 parent a2ec1c7 commit a4981f7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"symfony/http-foundation": "^2.8 || ^3.2 || ^4.0",
"symfony/http-kernel": "^2.8 || ^3.2 || ^4.0",
"symfony/options-resolver": "^2.8 || ^3.2 || ^4.0",
"symfony/security-core": "^2.8 || ^3.2 || ^4.0"
"symfony/security-core": "^2.8 || ^3.2 || ^4.0",
"twig/twig": "^1.35 || ^2.4"
},
"conflict": {
"sonata-project/admin-bundle": "<3.31 || >=4.0",
Expand Down
6 changes: 4 additions & 2 deletions src/Twig/Extension/SonataTimelineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
use Sonata\AdminBundle\Admin\Pool;
use Spy\Timeline\Model\ActionInterface;
use Spy\Timeline\Model\ComponentInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class SonataTimelineExtension extends \Twig_Extension
class SonataTimelineExtension extends AbstractExtension
{
/**
* @var Pool
Expand All @@ -39,7 +41,7 @@ public function __construct(Pool $pool = null)
public function getFunctions()
{
return [
new \Twig_SimpleFunction('sonata_timeline_generate_link', [$this, 'generateLink'], ['is_safe' => ['html']]),
new TwigFunction('sonata_timeline_generate_link', [$this, 'generateLink'], ['is_safe' => ['html']]),
];
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Spread/AdminSpreadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function testProcessMethod()
->disableOriginalConstructor()
->setMethods(['getUsers'])
->getMock();
$spread->expects($this->any())->method('getUsers')->will($this->returnValue($this->getFakeUsers()));
$spread->expects($this->any())->method('getUsers')->willReturn($this->getFakeUsers());

$collection = new EntryCollection();
$spread->process($action, $collection);
Expand Down
38 changes: 19 additions & 19 deletions tests/Twig/Extension/SonataTimelineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function setUp()
$this->pool->expects($this->any())
->method('getAdminByClass')
->with($this->equalTo('Acme\DemoBundle\Model\Demo'))
->will($this->returnValue($this->admin));
->willReturn($this->admin);

$this->twigExtension = new SonataTimelineExtension($this->pool);
}
Expand All @@ -61,21 +61,21 @@ public function testGenerateLink()
$this->admin->expects($this->once())
->method('hasRoute')
->with($this->equalTo('edit'))
->will($this->returnValue(true));
->willReturn(true);
$this->admin->expects($this->once())
->method('isGranted')
->with($this->equalTo('EDIT'))
->will($this->returnValue(true));
->willReturn(true);

$this->admin->expects($this->once())
->method('generateObjectUrl')
->with($this->equalTo('edit'), $this->anything())
->will($this->returnValue('acme/demo/2/edit'));
->willReturn('acme/demo/2/edit');

$this->admin->expects($this->once())
->method('toString')
->with($this->anything())
->will($this->returnValue('Text'));
->willReturn('Text');

$this->assertSame('<a href="acme/demo/2/edit">Text</a>', $this->twigExtension->generateLink($component, $action));
}
Expand All @@ -91,25 +91,25 @@ public function testGenerateLinkDisabledEdit()
$this->admin->expects($this->at(0))
->method('hasRoute')
->with($this->equalTo('edit'))
->will($this->returnValue(false));
->willReturn(false);
$this->admin->expects($this->at(1))
->method('hasRoute')
->with($this->equalTo('show'))
->will($this->returnValue(true));
->willReturn(true);
$this->admin->expects($this->at(2))
->method('isGranted')
->with($this->equalTo('SHOW'))
->will($this->returnValue(true));
->willReturn(true);

$this->admin->expects($this->once())
->method('generateObjectUrl')
->with($this->equalTo('show'), $this->anything())
->will($this->returnValue('acme/demo/2/show'));
->willReturn('acme/demo/2/show');

$this->admin->expects($this->once())
->method('toString')
->with($this->anything())
->will($this->returnValue('Text'));
->willReturn('Text');

$this->assertSame('<a href="acme/demo/2/show">Text</a>', $this->twigExtension->generateLink($component, $action));
}
Expand All @@ -125,29 +125,29 @@ public function testGenerateLinkNoEditPermission()
$this->admin->expects($this->at(0))
->method('hasRoute')
->with($this->equalTo('edit'))
->will($this->returnValue(true));
->willReturn(true);
$this->admin->expects($this->at(1))
->method('isGranted')
->with($this->equalTo('EDIT'))
->will($this->returnValue(false));
->willReturn(false);
$this->admin->expects($this->at(2))
->method('hasRoute')
->with($this->equalTo('show'))
->will($this->returnValue(true));
->willReturn(true);
$this->admin->expects($this->at(3))
->method('isGranted')
->with($this->equalTo('SHOW'))
->will($this->returnValue(true));
->willReturn(true);

$this->admin->expects($this->once())
->method('generateObjectUrl')
->with($this->equalTo('show'), $this->anything())
->will($this->returnValue('acme/demo/2/show'));
->willReturn('acme/demo/2/show');

$this->admin->expects($this->once())
->method('toString')
->with($this->anything())
->will($this->returnValue('Text'));
->willReturn('Text');

$this->assertSame('<a href="acme/demo/2/show">Text</a>', $this->twigExtension->generateLink($component, $action));
}
Expand All @@ -163,16 +163,16 @@ public function testGenerateLinkDisabledEditAndShow()
$this->admin->expects($this->at(0))
->method('hasRoute')
->with($this->equalTo('edit'))
->will($this->returnValue(false));
->willReturn(false);
$this->admin->expects($this->at(1))
->method('hasRoute')
->with($this->equalTo('show'))
->will($this->returnValue(false));
->willReturn(false);

$this->admin->expects($this->once())
->method('toString')
->with($this->anything())
->will($this->returnValue('Text'));
->willReturn('Text');

$this->assertSame('Text', $this->twigExtension->generateLink($component, $action));
}
Expand Down

0 comments on commit a4981f7

Please sign in to comment.