Created
April 12, 2013 16:43
-
-
Save msonnabaum/5373367 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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