Add tests for the "return $this" and fix it on the new method

This commit is contained in:
Joas Schilling 2015-11-17 09:26:13 +01:00
parent 705d208a8a
commit 2fde6a77d7
4 changed files with 62 additions and 21 deletions

View File

@ -50,7 +50,7 @@ class Action implements IAction {
$this->labelParsed = '';
$this->link = '';
$this->requestType = '';
$this->icon = '';
$this->primary = false;
}
/**
@ -99,6 +99,7 @@ class Action implements IAction {
/**
* @param $primary bool
* @return $this
* @throws \InvalidArgumentException if $primary is invalid
* @since 9.0.0
*/
@ -108,6 +109,7 @@ class Action implements IAction {
}
$this->primary = $primary;
return $this;
}
/**

View File

@ -62,6 +62,7 @@ interface IAction {
/**
* @param $primary bool
* @return $this
* @throws \InvalidArgumentException if $primary is invalid
* @since 9.0.0
*/

View File

@ -49,7 +49,7 @@ class ActionTest extends TestCase {
*/
public function testSetLabel($label) {
$this->assertSame('', $this->action->getLabel());
$this->action->setLabel($label);
$this->assertSame($this->action, $this->action->setLabel($label));
$this->assertSame($label, $this->action->getLabel());
}
@ -68,7 +68,7 @@ class ActionTest extends TestCase {
/**
* @dataProvider dataSetLabelInvalid
* @param string $label
* @param mixed $label
*
* @expectedException \InvalidArgumentException
*/
@ -90,7 +90,7 @@ class ActionTest extends TestCase {
*/
public function testSetParsedLabel($label) {
$this->assertSame('', $this->action->getParsedLabel());
$this->action->setParsedLabel($label);
$this->assertSame($this->action, $this->action->setParsedLabel($label));
$this->assertSame($label, $this->action->getParsedLabel());
}
@ -108,7 +108,7 @@ class ActionTest extends TestCase {
/**
* @dataProvider dataSetParsedLabelInvalid
* @param string $label
* @param mixed $label
*
* @expectedException \InvalidArgumentException
*/
@ -132,7 +132,7 @@ class ActionTest extends TestCase {
*/
public function testSetLink($link, $type) {
$this->assertSame('', $this->action->getLink());
$this->action->setLink($link, $type);
$this->assertSame($this->action, $this->action->setLink($link, $type));
$this->assertSame($link, $this->action->getLink());
$this->assertSame($type, $this->action->getRequestType());
}
@ -162,8 +162,8 @@ class ActionTest extends TestCase {
/**
* @dataProvider dataSetLinkInvalid
* @param string $link
* @param string $type
* @param mixed $link
* @param mixed $type
*
* @expectedException \InvalidArgumentException
*/
@ -171,6 +171,44 @@ class ActionTest extends TestCase {
$this->action->setLink($link, $type);
}
public function dataSetPrimary() {
return [
[true],
[false],
];
}
/**
* @dataProvider dataSetPrimary
* @param bool $primary
*/
public function testSetPrimary($primary) {
$this->assertSame(false, $this->action->isPrimary());
$this->assertSame($this->action, $this->action->setPrimary($primary));
$this->assertSame($primary, $this->action->isPrimary());
}
public function dataSetPrimaryInvalid() {
return [
[0],
[1],
[''],
[str_repeat('a', 257)],
[[]],
[[str_repeat('a', 257)]],
];
}
/**
* @dataProvider dataSetPrimaryInvalid
* @param mixed $primary
*
* @expectedException \InvalidArgumentException
*/
public function testSetPrimaryInvalid($primary) {
$this->action->setPrimary($primary);
}
public function testIsValid() {
$this->assertFalse($this->action->isValid());
$this->assertFalse($this->action->isValidParsed());

View File

@ -93,7 +93,7 @@ class NotificationTest extends TestCase {
*/
public function testSetApp($app) {
$this->assertSame('', $this->notification->getApp());
$this->notification->setApp($app);
$this->assertSame($this->notification, $this->notification->setApp($app));
$this->assertSame($app, $this->notification->getApp());
}
@ -121,7 +121,7 @@ class NotificationTest extends TestCase {
*/
public function testSetUser($user) {
$this->assertSame('', $this->notification->getUser());
$this->notification->setUser($user);
$this->assertSame($this->notification, $this->notification->setUser($user));
$this->assertSame($user, $this->notification->getUser());
}
@ -149,7 +149,7 @@ class NotificationTest extends TestCase {
*/
public function testSetTimestamp($timestamp) {
$this->assertSame(0, $this->notification->getTimestamp());
$this->notification->setTimestamp($timestamp);
$this->assertSame($this->notification, $this->notification->setTimestamp($timestamp));
$this->assertSame($timestamp, $this->notification->getTimestamp());
}
@ -182,7 +182,7 @@ class NotificationTest extends TestCase {
public function testSetObject($type, $id) {
$this->assertSame('', $this->notification->getObjectType());
$this->assertSame(0, $this->notification->getObjectId());
$this->notification->setObject($type, $id);
$this->assertSame($this->notification, $this->notification->setObject($type, $id));
$this->assertSame($type, $this->notification->getObjectType());
$this->assertSame($id, $this->notification->getObjectId());
}
@ -233,7 +233,7 @@ class NotificationTest extends TestCase {
public function testSetSubject($subject, $parameters) {
$this->assertSame('', $this->notification->getSubject());
$this->assertSame([], $this->notification->getSubjectParameters());
$this->notification->setSubject($subject, $parameters);
$this->assertSame($this->notification, $this->notification->setSubject($subject, $parameters));
$this->assertSame($subject, $this->notification->getSubject());
$this->assertSame($parameters, $this->notification->getSubjectParameters());
}
@ -262,7 +262,7 @@ class NotificationTest extends TestCase {
*/
public function testSetParsedSubject($subject) {
$this->assertSame('', $this->notification->getParsedSubject());
$this->notification->setParsedSubject($subject);
$this->assertSame($this->notification, $this->notification->setParsedSubject($subject));
$this->assertSame($subject, $this->notification->getParsedSubject());
}
@ -296,7 +296,7 @@ class NotificationTest extends TestCase {
public function testSetMessage($message, $parameters) {
$this->assertSame('', $this->notification->getMessage());
$this->assertSame([], $this->notification->getMessageParameters());
$this->notification->setMessage($message, $parameters);
$this->assertSame($this->notification, $this->notification->setMessage($message, $parameters));
$this->assertSame($message, $this->notification->getMessage());
$this->assertSame($parameters, $this->notification->getMessageParameters());
}
@ -325,7 +325,7 @@ class NotificationTest extends TestCase {
*/
public function testSetParsedMessage($message) {
$this->assertSame('', $this->notification->getParsedMessage());
$this->notification->setParsedMessage($message);
$this->assertSame($this->notification, $this->notification->setParsedMessage($message));
$this->assertSame($message, $this->notification->getParsedMessage());
}
@ -353,7 +353,7 @@ class NotificationTest extends TestCase {
*/
public function testSetLink($link) {
$this->assertSame('', $this->notification->getLink());
$this->notification->setLink($link);
$this->assertSame($this->notification, $this->notification->setLink($link));
$this->assertSame($link, $this->notification->getLink());
}
@ -387,7 +387,7 @@ class NotificationTest extends TestCase {
$action->expects($this->never())
->method('isValidParsed');
$this->notification->addAction($action);
$this->assertSame($this->notification, $this->notification->addAction($action));
$this->assertEquals([$action], $this->notification->getActions());
$this->assertEquals([], $this->notification->getParsedActions());
@ -422,7 +422,7 @@ class NotificationTest extends TestCase {
->method('isPrimary')
->willReturn(true);
$this->notification->addAction($action);
$this->assertSame($this->notification, $this->notification->addAction($action));
$this->setExpectedException('\InvalidArgumentException');
$this->notification->addAction($action);
@ -439,7 +439,7 @@ class NotificationTest extends TestCase {
$action->expects($this->never())
->method('isValid');
$this->notification->addParsedAction($action);
$this->assertSame($this->notification, $this->notification->addParsedAction($action));
$this->assertEquals([$action], $this->notification->getParsedActions());
$this->assertEquals([], $this->notification->getActions());
@ -474,7 +474,7 @@ class NotificationTest extends TestCase {
->method('isPrimary')
->willReturn(true);
$this->notification->addParsedAction($action);
$this->assertSame($this->notification, $this->notification->addParsedAction($action));
$this->setExpectedException('\InvalidArgumentException');
$this->notification->addParsedAction($action);