/**
  * $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);
 }
Пример #2
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']));
 }
 /**
  * @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]);
 }
Пример #4
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]));
 }
Пример #5
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]));
 }
Пример #6
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]);
 }
Пример #7
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]);
 }
Пример #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
 /**
  * @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'));
 }
Пример #10
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);
 }
Пример #11
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]);
 }
Пример #12
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]);
 }
Пример #13
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'));
 }
Пример #14
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]);
 }
Пример #15
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]);
 }
Пример #16
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]);
 }
Пример #17
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]));
 }
 /**
  * @covers ::updateSingleByPrimaryParameter
  */
 public function testUpdateSingleByPrimaryParameter()
 {
     $table = 'foobar';
     $primary = 'foo';
     $parameters = ['foo' => 'bar'];
     $this->testObj->table = $table;
     $this->testObj->primary = $primary;
     $this->testObj->parameters = $parameters;
     $columnArg = 'bazColumn';
     $valueArg = 'lorem ipsum';
     $expected = [$columnArg => $valueArg, $primary => $parameters[$primary]];
     $this->dbMock->expects($this->once())->method('newQuery')->with($this->identicalTo('update'), $this->identicalTo($table), $this->identicalTo(['columns' => [$columnArg]]))->willReturn($this->dbMock);
     $this->whereMock->expects($this->once())->method('Equals')->with($this->identicalTo($primary))->willReturn($this->dbMock);
     $this->stmntMock->expects($this->once())->method('Bind')->with($this->identicalTo(array_keys($expected)), $this->identicalTo($expected))->willReturn($this->stmntMock);
     $this->stmntMock->expects($this->once())->method('Execute');
     Utility::callMethod($this->testObj, 'updateSingleByPrimaryParameter', [$columnArg, $valueArg]);
 }
Пример #19
0
 /**
  * @covers ::standardAction
  * @depends testStandardAction
  */
 public function testStandardActionWithFetchedNamespace()
 {
     $name = 'foobar';
     $namespace = '\\baz\\bat\\fetched';
     $expected = $namespace . '\\actions\\' . $name;
     $this->actionMock->expects($this->once())->method('executeAction')->with($this->identicalTo($expected))->willReturn($this->renderableMock);
     $this->renderableMock->expects($this->once())->method('Render');
     $this->testObj->expects($this->once())->method('getCalledNamespace')->willReturn($namespace);
     Utility::callMethod($this->testObj, 'standardAction', [$name]);
 }
 /**
  * @covers ::interpolatePlaceholders
  * @dataProvider caseProvider
  */
 public function testInterpolatePlaceholders($view, $variables, $expected)
 {
     $this->assertEquals(Utility::callMethod($this->testObj, 'interpolatePlaceholders', [$view, $variables]), $expected);
 }
 /**
  * @covers ::validateBotCheckField
  */
 public function testValidateBotCheckField()
 {
     $this->serviceMock->expects($this->once())->method('validateField');
     Utility::callMethod($this->testObj, 'validateBotcheckField');
 }
Пример #22
0
 /**
  * @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);
 }
Пример #23
0
 /**
  * @covers ::addBotcheckField
  */
 public function testAddBotcheckField()
 {
     $content = 'lorem ipsum';
     $this->serviceMock->expects($this->once())->method('getField')->willReturn($content);
     $this->assertEquals($content, Utility::callMethod($this->testObj, 'addBotcheckField'));
 }