@@ -48,8 +48,139 @@ public function testCommandSetCacheItem()
4848 '--no-interaction ' => true
4949 ]);
5050
51- // Travis fix (.*) due to weird console screen width that truncate to next line
52- $ this ->assertRegExp ('/Cache item " ' . $ key . '" set to " ' . $ value . '" for ' . $ ttl . '/ ' , $ commandTester ->getDisplay ());
51+ $ this ->assertContains ('Cache item " ' . $ key . '" set to " ' . $ value . '" for ' . $ ttl , $ commandTester ->getDisplay ());
52+ }
53+
54+ public function testCommandSetCacheItemWithAutomaticTypeCastingBoolean ()
55+ {
56+ $ value = 'true ' ;
57+ $ ttl = \random_int (2 , 10 );
58+ $ key = 'test ' . \random_int (1000 , 1999 );
59+
60+ $ command = $ this ->application ->find ('phpfastcache:set ' );
61+ $ commandTester = new CommandTester ($ command );
62+ $ commandTester ->execute ([
63+ 'command ' => $ command ->getName (),
64+ 'driver ' => 'filecache ' ,
65+ 'key ' => $ key ,
66+ 'value ' => $ value ,
67+ 'ttl ' => $ ttl ,
68+ '-a ' => 1 ,
69+ '--no-interaction ' => true
70+ ]);
71+
72+ $ this ->assertContains ('Cache item " ' . $ key . '" set to " ' . $ value . '" for ' . $ ttl , $ commandTester ->getDisplay ());
73+ $ this ->assertContains ('(automatically type-casted to boolean) ' , $ commandTester ->getDisplay (), true );
74+ }
75+
76+ public function testCommandSetCacheItemWithAutomaticTypeCastingInteger ()
77+ {
78+ $ value = '1337 ' ;
79+ $ ttl = \random_int (2 , 10 );
80+ $ key = 'test ' . \random_int (1000 , 1999 );
81+
82+ $ command = $ this ->application ->find ('phpfastcache:set ' );
83+ $ commandTester = new CommandTester ($ command );
84+ $ commandTester ->execute ([
85+ 'command ' => $ command ->getName (),
86+ 'driver ' => 'filecache ' ,
87+ 'key ' => $ key ,
88+ 'value ' => $ value ,
89+ 'ttl ' => $ ttl ,
90+ '-a ' => 1 ,
91+ '--no-interaction ' => true
92+ ]);
93+
94+ $ this ->assertContains ('Cache item " ' . $ key . '" set to " ' . $ value . '" for ' . $ ttl , $ commandTester ->getDisplay ());
95+ $ this ->assertContains ('(automatically type-casted to integer) ' , $ commandTester ->getDisplay (), true );
96+ }
97+
98+ public function testCommandSetCacheItemWithAutomaticTypeCastingFloat ()
99+ {
100+ $ value = '1337.666 ' ;
101+ $ ttl = \random_int (2 , 10 );
102+ $ key = 'test ' . \random_int (1000 , 1999 );
103+
104+ $ command = $ this ->application ->find ('phpfastcache:set ' );
105+ $ commandTester = new CommandTester ($ command );
106+ $ commandTester ->execute ([
107+ 'command ' => $ command ->getName (),
108+ 'driver ' => 'filecache ' ,
109+ 'key ' => $ key ,
110+ 'value ' => $ value ,
111+ 'ttl ' => $ ttl ,
112+ '-a ' => 1 ,
113+ '--no-interaction ' => true
114+ ]);
115+
116+ $ this ->assertContains ('Cache item " ' . $ key . '" set to " ' . $ value . '" for ' . $ ttl , $ commandTester ->getDisplay ());
117+ $ this ->assertContains ('(automatically type-casted to double) ' , $ commandTester ->getDisplay (), true );
118+ }
119+
120+ public function testCommandSetCacheItemWithAutomaticTypeCastingNull ()
121+ {
122+ $ value = 'null ' ;
123+ $ ttl = \random_int (2 , 10 );
124+ $ key = 'test ' . \random_int (1000 , 1999 );
125+
126+ $ command = $ this ->application ->find ('phpfastcache:set ' );
127+ $ commandTester = new CommandTester ($ command );
128+ $ commandTester ->execute ([
129+ 'command ' => $ command ->getName (),
130+ 'driver ' => 'filecache ' ,
131+ 'key ' => $ key ,
132+ 'value ' => $ value ,
133+ 'ttl ' => $ ttl ,
134+ '-a ' => 1 ,
135+ '--no-interaction ' => true
136+ ]);
137+
138+ $ this ->assertContains ('Cache item " ' . $ key . '" set to " ' . $ value . '" for ' . $ ttl , $ commandTester ->getDisplay ());
139+ $ this ->assertContains ('(automatically type-casted to NULL) ' , $ commandTester ->getDisplay (), true );
140+ }
141+
142+ public function testCommandSetCacheItemWithAutomaticTypeCastingJson ()
143+ {
144+ $ value = '{"test": 1337} ' ;
145+ $ ttl = \random_int (2 , 10 );
146+ $ key = 'test ' . \random_int (1000 , 1999 );
147+
148+ $ command = $ this ->application ->find ('phpfastcache:set ' );
149+ $ commandTester = new CommandTester ($ command );
150+ $ commandTester ->execute ([
151+ 'command ' => $ command ->getName (),
152+ 'driver ' => 'filecache ' ,
153+ 'key ' => $ key ,
154+ 'value ' => $ value ,
155+ 'ttl ' => $ ttl ,
156+ '-a ' => 1 ,
157+ '--no-interaction ' => true
158+ ]);
159+
160+ $ this ->assertContains ('Cache item " ' . $ key . '" set to " ' . $ value . '" for ' . $ ttl , $ commandTester ->getDisplay ());
161+ $ this ->assertContains ('(automatically type-casted to array) ' , $ commandTester ->getDisplay (), true );
162+ }
163+
164+ public function testCommandSetCacheItemWithoutAutomaticTypeCasting ()
165+ {
166+ $ value = 'null ' ;
167+ $ ttl = \random_int (2 , 10 );
168+ $ key = 'test ' . \random_int (1000 , 1999 );
169+
170+ $ command = $ this ->application ->find ('phpfastcache:set ' );
171+ $ commandTester = new CommandTester ($ command );
172+ $ commandTester ->execute ([
173+ 'command ' => $ command ->getName (),
174+ 'driver ' => 'filecache ' ,
175+ 'key ' => $ key ,
176+ 'value ' => $ value ,
177+ 'ttl ' => $ ttl ,
178+ '-a ' => 0 ,
179+ '--no-interaction ' => true
180+ ]);
181+
182+ $ this ->assertContains ('Cache item " ' . $ key . '" set to " ' . $ value . '" for ' . $ ttl , $ commandTester ->getDisplay ());
183+ $ this ->assertNotContains ('(automatically type-casted to NULL) ' , $ commandTester ->getDisplay (), true );
53184 }
54185
55186 /**
0 commit comments