Пример #1
0
 /**
  * Case when passing validation is optional, expected to return result array
  * regardless of success
  * 
  * @covers ::getArguments
  */
 public function testGetsArgumentsWithoutMustValidate()
 {
     $expected = ['expected array'];
     $this->resultMock->expects($this->never())->method('getSuccess');
     $this->resultMock->expects($this->once())->method('getMessage')->willReturn($expected);
     $this->assertEquals($expected, Utility::callMethod($this->testObj, 'getArguments', [$this->arguments, false]));
 }
Пример #2
0
 /**
  * @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);
 }
Пример #3
0
 /**
  * @covers ::getMimeType
  */
 public function testGetMimeType()
 {
     $file = $this->rootDir . 'foo.txt';
     file_put_contents($file, 'lorem ipsum dolor');
     $expected = 'text/plain';
     $this->assertEquals($expected, Utility::callMethod($this->testObj, 'getMimeType', [$file]));
 }
Пример #4
0
 /**
  * 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 ::createThumbnail
  * @dataProvider argProvider
  */
 public function testCreateThumbnail($originalPath, $args)
 {
     $thumb = '/foo/bar/baz.jpg';
     $this->thumbMock->expects($this->once())->method('createThumbnail')->with($this->identicalTo($originalPath), $this->identicalTo($thumb), $this->identicalTo($args));
     $this->testObj->expects($this->once())->method('getThumbPath')->with($this->identicalTo($originalPath))->willReturn($thumb);
     Utility::callMethod($this->testObj, 'createThumbnail', [$originalPath, $args]);
 }
 /**
  * $array is empty, expected result is null
  * 
  * @covers ::pickRandomArrayElements
  */
 public function testPickRandomArrayElementsEmpty()
 {
     $array = [];
     $count = 3;
     $result = Utility::callMethod($this->testObj, 'pickRandomArrayElements', [$array, $count]);
     $this->assertEquals(null, $result);
 }
Пример #7
0
 /**
  * @covers ::getServerProp
  */
 public function testGetServerProp()
 {
     $_SERVER = ['foo' => 'bar', 'baz' => ''];
     $this->assertEquals($_SERVER['foo'], Utility::callMethod($this->testObj, 'getServerProp', ['foo']));
     $this->assertEquals($_SERVER['baz'], Utility::callMethod($this->testObj, 'getServerProp', ['baz']));
     $this->assertEquals(null, Utility::callMethod($this->testObj, 'getServerProp', ['other']));
 }
Пример #8
0
 /**
  * Expected failure if authentication check comes back false
  * 
  * @covers ::routeAuth
  * @depends testRouteAuthWithPermissionProperty
  */
 public function testRouteAuthFailedAuthentication()
 {
     $expected = 'foobar';
     $this->testObj->permission = $expected;
     $this->authMock->expects($this->once())->method('checkPermission')->with($this->identicalTo($expected))->willReturn(false);
     $this->setExpectedException('\\RuntimeException');
     Utility::callMethod($this->testObj, 'routeAuth');
 }
Пример #9
0
 /**
  * @depends testLogException
  * @covers ::logException
  */
 public function testLogExceptionDefaultLevel()
 {
     $exception = new \Exception('test exception');
     $dummyMessage = 'lorem ipsum';
     $this->loggerMock->expects($this->once())->method('exceptionToMessage')->With($exception)->willReturn($dummyMessage);
     $this->loggerMock->expects($this->once())->method('Log')->With($this->isType('string'), $this->identicalTo($dummyMessage));
     Utility::callMethod($this->testObj, 'logException', [$exception]);
 }
Пример #10
0
 /**
  * @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());
 }
Пример #11
0
 /**
  * @covers ::serveFlatView
  */
 public function testServeFlatViewWithNamespaceArg()
 {
     $view = 'foobar';
     $namespace = 'lorem\\ipsum';
     $expected = ['view' => $view, 'namespace' => $namespace];
     $this->testObj->expects($this->once())->method('standardView')->with($this->isType('string'), $this->identicalTo($expected));
     Utility::callMethod($this->testObj, 'serveFlatView', [$view, $namespace]);
 }
Пример #12
0
 /**
  * Test methods need to explictly call this method because we need to delay
  * testObj construction until after config has been set up
  */
 protected function setUpLogger($args = null)
 {
     $this->setUpConfig($args);
     $testedClass = '\\rakelley\\jhframe\\classes\\Logger';
     $mockedMethods = ['getConfig', 'getServerProp'];
     $this->testObj = $this->getMockBuilder($testedClass)->disableOriginalConstructor()->setMethods($mockedMethods)->getMock();
     $this->testObj->method('getConfig')->willReturn($this->configMock);
     Utility::callConstructor($this->testObj, [$this->systemMock]);
 }
Пример #13
0
 /**
  * @covers ::selectAll
  * @dataProvider resultProvider
  */
 public function testSelectAll($fetched)
 {
     $expected = $fetched ?: null;
     $table = 'foobar';
     $this->testObj->table = $table;
     $this->dbMock->expects($this->once())->method('newQuery')->with($this->identicalTo('select'), $this->identicalTo($table))->willReturn($this->dbMock);
     $this->stmntMock->expects($this->once())->method('FetchAll')->willReturn($fetched);
     $this->assertEquals($expected, Utility::callMethod($this->testObj, 'selectAll'));
 }
 /**
  * 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);
 }
Пример #15
0
 /**
  * @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());
 }
Пример #16
0
 /**
  * Set up config store and call test object constructor.  null is a valid
  * value for any arg so need to use array_key_exists instead of isset
  * 
  * @param array $args Args to pass to configMock
  */
 protected function setUpWithConfig(array $args = array())
 {
     $appName = array_key_exists('appName', $args) ? $args['appName'] : 'anystring';
     $dir = array_key_exists('dir', $args) ? $args['dir'] : null;
     $lifetime = array_key_exists('lifetime', $args) ? $args['lifetime'] : null;
     $this->configMock->expects($this->at(0))->method('Get')->with($this->identicalTo('APP'), $this->identicalTo('name'))->willReturn($appName);
     $this->configMock->expects($this->at(1))->method('Get')->with($this->identicalTo('ENV'), $this->identicalTo('cache_dir'))->willReturn($dir);
     $this->configMock->expects($this->at(2))->method('Get')->with($this->identicalTo('ENV'), $this->identicalTo('cache_lifetime'))->willReturn($lifetime);
     Utility::callConstructor($this->testObj, [$this->fileSystemMock]);
 }
Пример #17
0
 /**
  * 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);
 }
Пример #18
0
 /**
  * @covers ::getInput
  */
 public function testGetInputWithMixedClassParameters()
 {
     $args = ['list' => ['foo' => 'bar', 'baz' => 'bat'], 'method' => 'string'];
     $parameters = ['foo' => 'foo'];
     $expectedList = ['baz' => 'bat'];
     $values = ['baz' => 'baz'];
     $expectedResult = array_merge($parameters, $values);
     $this->testObj->parameters = $parameters;
     $this->inputMock->expects($this->once())->method('getList')->with($this->identicalTo($expectedList), $this->identicalTo($args['method']))->willReturn($values);
     $this->assertEquals(Utility::callMethod($this->testObj, 'getInput', $args), $expectedResult);
 }
Пример #19
0
 protected function setUpInput($rules = null)
 {
     $configInterface = '\\rakelley\\jhframe\\interfaces\\services\\IConfig';
     $testedClass = '\\rakelley\\jhframe\\classes\\Input';
     $configMock = $this->getMock($configInterface);
     $configMock->method('Get')->with($this->identicalTo('APP'), $this->identicalTo('input_rules'))->willReturn($rules);
     $mockedMethods = ['getConfig'];
     $this->testObj = $this->getMockBuilder($testedClass)->disableOriginalConstructor()->setMethods($mockedMethods)->getMock();
     $this->testObj->method('getConfig')->willReturn($configMock);
     Utility::callConstructor($this->testObj, [$this->filterMock, $this->ioMock]);
 }
Пример #20
0
 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);
 }
Пример #21
0
 /**
  * @covers ::insertAll
  */
 public function testInsertAll()
 {
     $table = 'foobar';
     $columns = ['foobar', 'bazbat'];
     $values = ['foo', 'bar', 'baz'];
     $this->testObj->table = $table;
     $this->testObj->columns = $columns;
     $this->dbMock->expects($this->once())->method('newQuery')->with($this->identicalTo('insert'), $this->identicalTo($table), $this->identicalTo(['columns' => $columns]))->willReturn($this->dbMock);
     $this->stmntMock->expects($this->once())->method('Bind')->with($this->identicalTo($columns), $this->identicalTo($values))->willReturn($this->stmntMock);
     $this->stmntMock->expects($this->once())->method('Execute');
     Utility::callMethod($this->testObj, 'insertAll', [$values]);
 }
Пример #22
0
 protected function setUp()
 {
     $configInterface = '\\rakelley\\jhframe\\interfaces\\services\\IConfig';
     $systemInterface = '\\rakelley\\jhframe\\interfaces\\services\\IFileSystemAbstractor';
     $testedClass = '\\rakelley\\jhframe\\classes\\FlatView';
     $configMock = $this->getMock($configInterface);
     $configMock->method('Get')->with($this->identicalTo('ENV'), $this->identicalTo('root_dir'))->willReturn($this->rootDir);
     $this->systemMock = $this->getMock($systemInterface);
     $mockedMethods = ['getConfig'];
     $this->testObj = $this->getMockBuilder($testedClass)->disableOriginalConstructor()->setMethods($mockedMethods)->getMock();
     $this->testObj->method('getConfig')->willReturn($configMock);
     Utility::callConstructor($this->testObj, [$this->systemMock]);
 }
Пример #23
0
 /**
  * @covers ::deleteOnValues
  * @dataProvider caseProvider
  */
 public function testDeleteOnValues($arg)
 {
     $primary = 'bazColumn';
     $table = 'foobar';
     $this->testObj->primary = $primary;
     $this->testObj->table = $table;
     $values = ['foo', 'bar', 'baz'];
     $expectedCol = $arg ?: $primary;
     $this->dbMock->expects($this->once())->method('newQuery')->with($this->identicalTo('delete'), $this->identicalTo($table))->willReturn($this->dbMock);
     $this->whereMock->expects($this->once())->method('In')->with($this->identicalTo($expectedCol), $this->identicalTo($values))->willReturn($this->dbMock);
     $this->stmntMock->expects($this->once())->method('Execute')->with($this->identicalTo($values));
     Utility::callMethod($this->testObj, 'deleteOnValues', [$values, $arg]);
 }
Пример #24
0
 /**
  * @covers ::getCount
  */
 public function testGetCount()
 {
     $count = 10;
     $table = 'foobar';
     $pdoStmntMock = $this->getMockBuilder('\\stdClass')->setMethods(['fetchColumn'])->getMock();
     $pdoStmntMock->expects($this->once())->method('fetchColumn')->willReturn($count);
     $this->testObj->table = $table;
     $this->dbMock->expects($this->once())->method('newQuery')->with($this->identicalTo('select'), $this->identicalTo($table), $this->identicalTo(['select' => 'count(*)']))->willReturn($this->dbMock);
     $this->dbMock->expects($this->once())->method('stripTicks')->willReturn($this->dbMock);
     $this->stmntMock->expects($this->once())->method('Execute')->willReturn($this->stmntMock);
     $this->stmntMock->expects($this->once())->method('returnStatement')->willReturn($pdoStmntMock);
     $this->assertEquals($count, Utility::callMethod($this->testObj, 'getCount'));
 }
Пример #25
0
 /**
  * @covers ::insertAutoPrimary
  * @dataProvider caseProvider
  */
 public function testInsertAutoPrimary($primary)
 {
     $columns = ['foo', 'bar', 'baz', 'bat'];
     $expected = array_values(array_diff($columns, (array) $primary));
     $values = ['lorem', 'ipsum'];
     $table = 'foobar';
     $this->testObj->primary = $primary;
     $this->testObj->columns = $columns;
     $this->testObj->table = $table;
     $this->dbMock->expects($this->once())->method('newQuery')->with($this->identicalTo('insert'), $this->identicalTo($table), $this->identicalTo(['columns' => $expected]))->willReturn($this->dbMock);
     $this->stmntMock->expects($this->once())->method('Bind')->with($this->identicalTo($expected), $this->identicalTo($values))->willReturn($this->stmntMock);
     $this->stmntMock->expects($this->once())->method('Execute');
     Utility::callMethod($this->testObj, 'insertAutoPrimary', [$values]);
 }
Пример #26
0
 /**
  * Set up config store and call test object constructor.  null is a valid
  * value for any arg so need to use array_key_exists instead of isset
  * 
  * @param array|null $args Args to pass to configMock
  */
 protected function setUpWithConfig(array $args = null)
 {
     $isAjax = array_key_exists('isAjax', $args) ? $args['isAjax'] : false;
     $envType = array_key_exists('envType', $args) ? $args['envType'] : 'production';
     $publicDir = array_key_exists('publicDir', $args) ? $args['publicDir'] : 'a string';
     $errorView = array_key_exists('errorView', $args) ? $args['errorView'] : 'a string';
     $logLevel = array_key_exists('logLevel', $args) ? $args['logLevel'] : null;
     $this->configMock->expects($this->at(0))->method('Get')->with($this->identicalTo('ENV'), $this->identicalTo('is_ajax'))->willReturn($isAjax);
     $this->configMock->expects($this->at(1))->method('Get')->with($this->identicalTo('ENV'), $this->identicalTo('type'))->willReturn($envType);
     $this->configMock->expects($this->at(2))->method('Get')->with($this->identicalTo('ENV'), $this->identicalTo('public_dir'))->willReturn($publicDir);
     $this->configMock->expects($this->at(3))->method('Get')->with($this->identicalTo('APP'), $this->identicalTo('error_view'))->willReturn($errorView);
     $this->configMock->expects($this->at(4))->method('Get')->with($this->identicalTo('APP'), $this->identicalTo('exception_log_level'))->willReturn($logLevel);
     Utility::callConstructor($this->testObj, [$this->containerMock, $this->fileMock, $this->ioMock]);
 }
Пример #27
0
 /**
  * @covers ::updateByPrimary
  * @dataProvider caseProvider
  */
 public function testUpdateByPrimary($primary, $expectedOperator)
 {
     $columns = ['foo', 'bar', 'baz', 'bat'];
     $table = 'foobar';
     $expectedCols = array_values(array_diff($columns, (array) $primary));
     $values = ['lorem', 'ipsum', 'dolor'];
     $this->testObj->primary = $primary;
     $this->testObj->columns = $columns;
     $this->testObj->table = $table;
     $this->dbMock->expects($this->once())->method('newQuery')->with($this->identicalTo('update'), $this->identicalTo($table), $this->identicalTo(['columns' => $expectedCols]))->willReturn($this->dbMock);
     $this->whereMock->expects($this->once())->method('Equals')->with($this->identicalTo($primary), $this->identicalTo($expectedOperator))->willReturn($this->dbMock);
     $this->stmntMock->expects($this->once())->method('Bind')->with($this->identicalTo($columns), $this->identicalTo($values))->willReturn($this->stmntMock);
     $this->stmntMock->expects($this->once())->method('Execute');
     Utility::callMethod($this->testObj, 'updateByPrimary', [$values]);
 }
Пример #28
0
 /**
  * @covers ::deleteByParameter
  * @dataProvider caseProvider
  */
 public function testDeleteByParameter($arg, $expectedOperator)
 {
     $primary = 'bazColumn';
     $parameters = ['foo' => 'bar', 'baz' => 'bat'];
     $table = 'foobar';
     $this->testObj->primary = $primary;
     $this->testObj->parameters = $parameters;
     $this->testObj->table = $table;
     $expectedKeys = $arg ?: $primary;
     $this->dbMock->expects($this->once())->method('newQuery')->with($this->identicalTo('delete'), $this->identicalTo($table))->willReturn($this->dbMock);
     $this->whereMock->expects($this->once())->method('Equals')->with($this->identicalTo($expectedKeys), $this->identicalTo($expectedOperator))->willReturn($this->dbMock);
     $this->stmntMock->expects($this->once())->method('Bind')->with($this->identicalTo($expectedKeys), $this->identicalTo($parameters))->willReturn($this->stmntMock);
     $this->stmntMock->expects($this->once())->method('Execute');
     Utility::callMethod($this->testObj, 'deleteByParameter', [$arg]);
 }
Пример #29
0
 /**
  * @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());
 }
Пример #30
0
 /**
  * @covers ::selectOneByParameter
  * @dataProvider caseProvider
  */
 public function testSelectOneByParameter($methodArg, $expectedOperator, $fetched)
 {
     $primary = 'bazColumn';
     $parameters = ['foo' => 'bar', 'baz' => 'bat'];
     $table = 'foobar';
     $this->testObj->primary = $primary;
     $this->testObj->parameters = $parameters;
     $this->testObj->table = $table;
     $expectedKeys = $methodArg ?: $primary;
     $expectedResult = $fetched ?: null;
     $this->dbMock->expects($this->once())->method('newQuery')->with($this->identicalTo('select'), $this->identicalTo($table))->willReturn($this->dbMock);
     $this->whereMock->expects($this->once())->method('Equals')->with($this->identicalTo($expectedKeys), $this->identicalTo($expectedOperator))->willReturn($this->dbMock);
     $this->stmntMock->expects($this->once())->method('Bind')->with($this->identicalTo($expectedKeys), $this->identicalTo($parameters))->willReturn($this->stmntMock);
     $this->stmntMock->expects($this->once())->method('Fetch')->willReturn($fetched);
     $this->assertEquals($expectedResult, Utility::callMethod($this->testObj, 'selectOneByParameter', [$methodArg]));
 }