Skip to content

Instantly share code, notes, and snippets.

@msonnabaum
Created April 12, 2013 16:43
Show Gist options
  • Save msonnabaum/5373367 to your computer and use it in GitHub Desktop.
Save msonnabaum/5373367 to your computer and use it in GitHub Desktop.
<?php
namespace Drupal\Tests\Core;
use Drupal\Tests\UnitTestCase;
class SomeClass {
function someMethod() {
$executable = \Drupal\views\Views::executableFactory();
$item = $executable->getItem('somedisplayid', 'sometype', 'someid');
if ($item === NULL) {
return 'wtf!';
}
}
}
class SomeTest extends UnitTestCase {
function testSomething() {
$mock_exec = $this->getMockBuilder('Drupal\views\ViewExecutable')
->disableOriginalConstructor()
->getMock();
$mock_exec->expects($this->any())
->method('getItem')
->will($this->returnCallback(function() {
return NULL;
}));
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container->expects($this->any())
->method('get')
->with($this->equalTo('views.executable'))
->will($this->returnCallback(function() use ($mock_exec) {return $mock_exec;}));
\Drupal::setContainer($container);
$someclass = new Someclass;
$this->assertEquals('wtf!', $someclass->someMethod());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment