Skip to content

Commit 9b9470e

Browse files
committed
Merge branch 'feature/issue-7' into develop
2 parents 02e98a4 + 7bdf6c5 commit 9b9470e

14 files changed

+114
-7
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ before_install:
1414
- composer self-update
1515

1616
install:
17-
- composer install --no-dev
17+
- composer install
1818

1919
script:
20-
- phpunit --coverage-text --coverage-clover=coverage.clover
20+
- ./vendor/phpunit/phpunit/phpunit --coverage-text --coverage-clover=coverage.clover
2121

2222
after_script:
2323
- wget https://scrutinizer-ci.com/ocular.phar

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"php" : ">=5.3.3"
66
},
77
"require-dev": {
8-
"friendsofphp/php-cs-fixer": "~2.0"
8+
"friendsofphp/php-cs-fixer": "~2.0",
9+
"phpunit/phpunit": "~4.0"
910
},
1011
"license" : "MIT",
1112
"keywords" : [ "php", "generator" ],
@@ -25,4 +26,4 @@
2526
"email" : "[email protected]",
2627
"role" : "Owner"
2728
} ]
28-
}
29+
}

src/Element/AbstractAssignedValueElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct($name, $value = null, $access = parent::ACCESS_PUBLI
3131
public function setValue($value)
3232
{
3333
if ($this->getAcceptNonScalarValue() === false && !is_scalar($value) && $value !== null) {
34-
throw new \InvalidArgumentException(sprintf('Value of type "%s" is not a valid scalar value', gettype($value)));
34+
throw new \InvalidArgumentException(sprintf('Value of type "%s" is not a valid scalar value for %s object', gettype($value), $this->getCalledClass()));
3535
}
3636
$this->value = $value;
3737
return $this;

src/Element/AbstractElement.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct($name)
3232
public function setName($name)
3333
{
3434
if (!self::nameIsValid($name)) {
35-
throw new \InvalidArgumentException(sprintf('Name "%s" is invalid, please provide a valid name', $name));
35+
throw new \InvalidArgumentException(sprintf('Name "%s" is invalid when instantiating %s object', $name, $this->getCalledClass()));
3636
}
3737
$this->name = $name;
3838
return $this;
@@ -84,7 +84,7 @@ public function toString($indentation = null)
8484
{
8585
$lines = array(
8686
$this->getToStringDeclaration($indentation),
87-
$this->getToStringBeforeChildren($indentation),
87+
$this->getToStringBeforeChildren($indentation)
8888
);
8989
foreach ($this->getChildren() as $child) {
9090
$lines[] = $this->getChildContent($child, $indentation + ($this->useBracketsForChildren() ? 1 : 0));
@@ -329,4 +329,11 @@ public function getIndentedString($string, $indentation = null)
329329
}
330330
return implode(self::BREAK_LINE_CHAR, $strings);
331331
}
332+
/**
333+
* @return string
334+
*/
335+
final public function getCalledClass()
336+
{
337+
return substr(get_called_class(), strrpos(get_called_class(), '\\') + 1);
338+
}
332339
}

tests/Element/PhpAnnotationTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,13 @@ public function testHasContent()
6868

6969
$this->assertTrue($annotation->hasContent());
7070
}
71+
72+
public function testExceptionMessageOnName()
73+
{
74+
try {
75+
new PhpAnnotation(0, '');
76+
} catch (\InvalidArgumentException $e) {
77+
$this->assertSame('Name "0" is invalid when instantiating PhpAnnotation object', $e->getMessage());
78+
}
79+
}
7180
}

tests/Element/PhpClassTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,13 @@ public function testExtendsFromNamespace()
255255

256256
$this->assertSame("class Foo extends \\DOMDocument\n{\n}", $class->toString());
257257
}
258+
259+
public function testExceptionMessageOnName()
260+
{
261+
try {
262+
new PhpClass(0);
263+
} catch (\InvalidArgumentException $e) {
264+
$this->assertSame('Name "0" is invalid when instantiating PhpClass object', $e->getMessage());
265+
}
266+
}
258267
}

tests/Element/PhpConstantTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,22 @@ public function testGetChildrenTypes()
131131

132132
$this->assertSame(array(), $constant->getChildrenTypes());
133133
}
134+
135+
public function testExceptionMessageOnName()
136+
{
137+
try {
138+
new PhpConstant(0);
139+
} catch (\InvalidArgumentException $e) {
140+
$this->assertSame('Name "0" is invalid when instantiating PhpConstant object', $e->getMessage());
141+
}
142+
}
143+
144+
public function testExceptionMessageOnValue()
145+
{
146+
try {
147+
new PhpConstant('Foo', new \stdClass());
148+
} catch (\InvalidArgumentException $e) {
149+
$this->assertSame('Value of type "object" is not a valid scalar value for PhpConstant object', $e->getMessage());
150+
}
151+
}
134152
}

tests/Element/PhpFileTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,13 @@ public function testAnnotationClassMethodBlockToString()
8181

8282
$this->assertSame("<?php\n/**\n * date is the key\n * time is the core key\n */\nclass Foo\n{\n public function Bar()\n {\n }\n}\n", $file->toString());
8383
}
84+
85+
public function testExceptionMessageOnName()
86+
{
87+
try {
88+
new PhpFile(0);
89+
} catch (\InvalidArgumentException $e) {
90+
$this->assertSame('Name "0" is invalid when instantiating PhpFile object', $e->getMessage());
91+
}
92+
}
8493
}

tests/Element/PhpFunctionParameterTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,13 @@ public function testToStringWithNamespace()
5555

5656
$this->assertSame('My\Name\Space $foo = null', $functionParameter->toString());
5757
}
58+
59+
public function testExceptionMessageOnName()
60+
{
61+
try {
62+
new PhpFunctionParameter(0);
63+
} catch (\InvalidArgumentException $e) {
64+
$this->assertSame('Name "0" is invalid when instantiating PhpFunctionParameter object', $e->getMessage());
65+
}
66+
}
5867
}

tests/Element/PhpFunctionTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,13 @@ public function testToStringWithBody()
114114

115115
$this->assertSame("function foo(\$bar, \$demo = 1, \$sample = null, \$deamon = true)\n{\n \$bar = 1;\n return \$bar;\n}", $function->toString());
116116
}
117+
118+
public function testExceptionMessageOnName()
119+
{
120+
try {
121+
new PhpFunction(0);
122+
} catch (\InvalidArgumentException $e) {
123+
$this->assertSame('Name "0" is invalid when instantiating PhpFunction object', $e->getMessage());
124+
}
125+
}
117126
}

0 commit comments

Comments
 (0)