/** * @covers ::__construct * @depends testConstruct */ public function testConstructFailure() { Utility::setProperties(['rootDir' => null], $this->testObj); $this->testObj->expects($this->once())->method('getRootConstant')->willReturn(null); $this->setExpectedException('\\RuntimeException'); Utility::callConstructor($this->testObj); }
/** * Expected to not reset properties when setParameters called with identical * parameters * * @covers ::setParameters * @depends testSetParameters */ public function testSetParametersNoChange() { $parameters = ['baz' => 'bat', 'burz' => 'um']; Utility::setProperties(['parameters' => $parameters], $this->testObj); $this->testObj->expects($this->never())->method('resetProperties'); $this->testObj->setParameters($parameters); }
/** * @covers ::touchesData */ public function testTouchesData() { $default = true; $this->assertEquals($default, $this->testObj->touchesData()); $value = false; Utility::setProperties(['touchesData' => $value], $this->testObj); $this->assertEquals($value, $this->testObj->touchesData()); }
/** * Case when handler is not set, should not be possible but exceptions * must not ever leak from Initiate so should be covered anyway * * @covers ::Initiate * @covers ::handlerFailure * @depends testInitiateExceptionRaised */ public function testInitiateNoHandler() { Utility::setProperties(['handler' => null], $this->testObj); $e = new \Exception('test message'); $this->handlerMock->expects($this->never())->method('Handle'); $this->ioMock->expects($this->once())->method('toErrorLog')->With($this->isType('string')); $this->ioMock->expects($this->once())->method('toExit')->With($this->isType('string')); $this->testObj->Initiate($e); }
/** * @covers ::returnView */ public function testReturnView() { $content = 'foobar'; $type = 'foo'; $meta = ['foo' => 'bar']; $expected = ['content' => $content, 'type' => $type, 'meta' => $meta]; $properties = ['viewContent' => $content, 'contentType' => $type, 'metaData' => $meta]; Utility::setProperties($properties, $this->testObj); $this->assertEquals($expected, $this->testObj->returnView()); }
/** * Ensure empty fetch case is safe for existing data * * @depends testFetchMetaDataEmptyFetch * @covers ::fetchMetaData */ public function testFetchMetaDataEmptyFetchWithExisting() { $route = 'foobar'; $data = null; $existing = ['lorem' => 'ipsum']; Utility::setProperties(['metaRoute' => $route], $this->testObj); $this->testObj->metaData = $existing; $this->serviceMock->expects($this->once())->method('getPage')->with($this->identicalTo($route))->willReturn($data); $this->testObj->fetchMetaData(); $this->assertEquals($existing, $this->testObj->metaData); }
protected function setUp() { $class = $this->testedClass; $configInterface = $class::INTERFACE_CONFIG; $this->configMock = $this->getMock($configInterface); $locatorInterface = $class::INTERFACE_LOCATOR; $this->locatorMock = $this->getMock($locatorInterface); $mockedMethods = ['getServerProp']; $this->testObj = $this->getMockBuilder($this->testedClass)->disableOriginalConstructor()->setMethods($mockedMethods)->getMock(); $props = ['config' => $this->configMock, 'locator' => $this->locatorMock, 'instance' => $this->testObj]; Utility::setProperties($props, $this->testObj); }
protected function setUp() { $connectionClass = '\\stdClass'; //can't mock \PDO directly $statementClass = '\\stdClass'; //can't mock \PDOStatement directly $testedClass = '\\rakelley\\jhframe\\classes\\StatementAbstractor'; $this->testObj = $this->getMockBuilder($testedClass)->disableOriginalConstructor()->setMethods(null)->getMock(); $this->statementMock = $this->getMockBuilder($statementClass)->disableOriginalConstructor()->setMethods(['bindValue', 'execute', 'fetch', 'fetchAll'])->getMock(); $this->connectionMock = $this->getMockBuilder($connectionClass)->disableOriginalConstructor()->setMethods(['prepare'])->getMock(); $properties = ['connection' => $this->connectionMock, 'stmnt' => $this->statementMock]; Utility::setProperties($properties, $this->testObj); }
/** * @covers ::getContent * @dataProvider contentProvider * @depends testGetSuccess * @depends testGetError * @depends testGetMessage */ public function testGetContent($properties, $expected) { if (isset($properties['content'])) { Utility::setProperties(['content' => $properties['content']], $this->testObj); } if (isset($properties['success'])) { $this->testObj->setSuccess($properties['success']); } if (isset($properties['error'])) { $this->testObj->setError($properties['error']); } if (isset($properties['message'])) { $this->testObj->setMessage($properties['message']); } $this->assertEquals($expected, $this->testObj->getContent()); }
/** * @covers ::matchRoute * @dataProvider badRouteProvider */ public function testMatchRouteFailure($routes, $type, $route) { Utility::setProperties(['routes' => $routes], $this->testObj); $this->setExpectedException('\\UnexpectedValueException'); $this->testObj->matchRoute($type, $route); }
protected function setUpProperties(array $properties) { Utility::setProperties(['properties' => $properties], $this->testObj); }
/** * @covers ::getResult */ public function testGetResult() { $validated = ['foo' => 'bar', 'baz' => 'bat']; Utility::setProperties(['validated' => $validated], $this->testObj); $this->assertEquals($validated, $this->testObj->getResult()); }
protected function setUpStored(array $stored) { Utility::setProperties(['config' => $stored], $this->testObj); }
/** * @covers ::Render * @covers ::handleType * @depends testRenderJson */ public function testRenderWithAjax() { Utility::setProperties(['isAjax' => true], $this->testObj); $renderable = ['content' => 'lorem ipsum', 'type' => IRenderer::TYPE_PLAIN]; $this->testRenderJson($renderable); }
/** * @covers ::makeRelative */ public function testMakeRelative() { $properties = ['directory' => '/foo/bar/baz/', 'relativePath' => 'baz/']; Utility::setProperties($properties, $this->testObj); $path = '/foo/bar/baz/bat.txt'; $expected = 'baz/bat.txt'; $this->assertEquals($expected, $this->testObj->makeRelative($path)); }
/** * @covers ::standardConstructor * @depends testConstructView */ public function testStandardConstructorWithMessage() { $message = 'success message'; $fields = ['footextarea' => ['type' => 'textarea', 'lorem' => 'ipsum']]; $properties = ['attributes' => ['any', 'array'], 'data' => [], 'fields' => $fields, 'title' => null]; Utility::setProperties($properties, $this->testObj); $this->builderMock->method('combineAttributes')->willReturn('attribute_string'); $this->builderMock->method('constructTextarea')->willReturn('textarea_string'); $this->builderMock->expects($this->once())->method('constructStatusBlock')->with($this->identicalTo($message))->willReturn('statusblock_string'); $result = Utility::callMethod($this->testObj, 'standardConstructor', [$message]); $this->assertTrue(strlen($result) > 1); }