@@ -47,7 +47,7 @@ public function testCanNotSetAttributeIfRelationshipExists()
4747 * @param string $name
4848 * @expectedException \InvalidArgumentException
4949 * @expectedExceptionMessage Can not use a reserved name
50- * @dataProvider invalidAttributeNames
50+ * @dataProvider reservedAttributeNames
5151 */
5252 public function testAttributeCanNotHaveReservedNames (string $ name )
5353 {
@@ -59,19 +59,73 @@ public function testAttributeCanNotHaveReservedNames(string $name)
5959 * @param string $name
6060 * @expectedException \InvalidArgumentException
6161 * @expectedExceptionMessage Can not use a reserved name
62- * @dataProvider invalidAttributeNames
62+ * @dataProvider reservedAttributeNames
6363 */
6464 public function testRelationshipCanNotHaveReservedNames (string $ name )
6565 {
6666 $ res = new ResourceObject ('books ' , 'abc ' );
6767 $ res ->setRelationship ($ name , Relationship::fromMeta (Meta::fromArray (['a ' => 'b ' ])));
6868 }
6969
70- public function invalidAttributeNames (): array
70+ /**
71+ * @param string $name
72+ * @expectedException \OutOfBoundsException
73+ * @expectedExceptionMessage Not a valid attribute name
74+ * @dataProvider invalidAttributeNames
75+ */
76+ public function testAttributeNameIsNotValid (string $ name )
77+ {
78+ $ res = new ResourceObject ('books ' , 'abc ' );
79+ $ res ->setAttribute ($ name , 1 );
80+ }
81+
82+ /**
83+ * @param string $name
84+ * @dataProvider validAttributeNames
85+ */
86+ public function testAttributeNameIsValid (string $ name )
87+ {
88+ $ res = new ResourceObject ('books ' , 'abc ' );
89+ $ res ->setAttribute ($ name , 1 );
90+ $ this ->assertTrue (true );
91+ }
92+
93+ public function reservedAttributeNames (): array
7194 {
7295 return [
7396 ['id ' ],
7497 ['type ' ],
7598 ];
7699 }
100+
101+ public function invalidAttributeNames (): array
102+ {
103+ return [
104+ ['_abcde ' ],
105+ ['abcd_ ' ],
106+ ['abc$EDS ' ],
107+ ['#abcde ' ],
108+ ['abcde( ' ],
109+ ['b_ ' ],
110+ ['_a ' ],
111+ ['$ab_c-d ' ],
112+ ['-abc ' ],
113+ ];
114+ }
115+
116+ public function validAttributeNames (): array
117+ {
118+ return [
119+ ['abcd ' ],
120+ ['abcA4C ' ],
121+ ['abc_d3f45 ' ],
122+ ['abd_eca ' ],
123+ ['a ' ],
124+ ['b ' ],
125+ ['ab ' ],
126+ ['a-bc_de ' ],
127+ ['abcéêçèÇ_n ' ],
128+ ['abc 汉字 abc ' ],
129+ ];
130+ }
77131}
0 commit comments