From cdb75d97d58750f9006d84751bd991236cd7b2c1 Mon Sep 17 00:00:00 2001 From: TrueGit Date: Tue, 7 Jul 2015 14:47:43 -0400 Subject: [PATCH] Edit tests in unit-testing.rst to fix error In symfony-docs/create_framework/unit-testing.rst, in the "FrameworkTest" class, make following changes to protected method named "getFrameworkForException" and to test method named "testControllerResponse": (i) add mock RequestContext, and (ii) add to mock URLMatcherInterface the expectation that its "getContext" method will be called and will return the mock RequestContext. Reason: Prior to these changes, running phpunit while following the tutorial causes php error with message: "Fatal error: Call to a member function fromRequest() on null in [path/to/]example.com/src/Simplex/Framework.php on line 24" The line 24 referred to in the foregoing error message is the first line of the Framework class's handle method: "$this->matcher->getContext()->fromRequest($request);" --- create_framework/unit-testing.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/create_framework/unit-testing.rst b/create_framework/unit-testing.rst index b34b3a76e2d..90ab5a32868 100644 --- a/create_framework/unit-testing.rst +++ b/create_framework/unit-testing.rst @@ -91,6 +91,12 @@ We are now ready to write our first test:: protected function getFrameworkForException($exception) { $matcher = $this->getMock('Symfony\Component\Routing\Matcher\UrlMatcherInterface'); + $context = $this->getMock('Symfony\Component\Routing\RequestContext'); + $matcher + ->expects($this->once()) + ->method('getContext') + ->willReturn($context) + ; $matcher ->expects($this->once()) ->method('match') @@ -141,6 +147,12 @@ Response:: public function testControllerResponse() { $matcher = $this->getMock('Symfony\Component\Routing\Matcher\UrlMatcherInterface'); + $context = $this->getMock('Symfony\Component\Routing\RequestContext'); + $matcher + ->expects($this->once()) + ->method('getContext') + ->willReturn($context) + ; $matcher ->expects($this->once()) ->method('match')