Skip to content

Commit 4bd9f6f

Browse files
committed
Add tests for magic __isset methods
1 parent 6ca6b7d commit 4bd9f6f

6 files changed

Lines changed: 157 additions & 5 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
namespace CodeIgniter\Commands;
3+
4+
use Config\Services;
5+
use CodeIgniter\CLI\CommandRunner;
6+
7+
class BaseCommandTest extends \CIUnitTestCase
8+
{
9+
protected $logger;
10+
protected $runner;
11+
12+
protected function setUp()
13+
{
14+
parent::setUp();
15+
$this->logger = Services::logger();
16+
$this->runner = new CommandRunner();
17+
}
18+
19+
public function testMagicIssetTrue()
20+
{
21+
$command = new \Tests\Support\Commands\AppInfo($this->logger, $this->runner);
22+
23+
$this->assertTrue(isset($command->group));
24+
}
25+
26+
public function testMagicIssetFalse()
27+
{
28+
$command = new \Tests\Support\Commands\AppInfo($this->logger, $this->runner);
29+
30+
$this->assertFalse(isset($command->foobar));
31+
}
32+
33+
public function testMagicGet()
34+
{
35+
$command = new \Tests\Support\Commands\AppInfo($this->logger, $this->runner);
36+
37+
$this->assertEquals('demo', $command->group);
38+
}
39+
40+
public function testMagicGetMissing()
41+
{
42+
$command = new \Tests\Support\Commands\AppInfo($this->logger, $this->runner);
43+
44+
$this->assertNull($command->foobar);
45+
}
46+
}

tests/system/Database/BaseConnectionTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,40 @@ public function testStoresConnectionTimings()
128128
$this->assertGreaterThan($start, $db->getConnectStart());
129129
$this->assertGreaterThan(0.0, $db->getConnectDuration());
130130
}
131+
132+
//--------------------------------------------------------------------
133+
134+
public function testMagicIssetTrue()
135+
{
136+
$db = new MockConnection($this->options);
137+
138+
$this->assertTrue(isset($db->charset));
139+
}
140+
141+
//--------------------------------------------------------------------
142+
143+
public function testMagicIssetFalse()
144+
{
145+
$db = new MockConnection($this->options);
146+
147+
$this->assertFalse(isset($db->foobar));
148+
}
149+
150+
//--------------------------------------------------------------------
151+
152+
public function testMagicGet()
153+
{
154+
$db = new MockConnection($this->options);
155+
156+
$this->assertEquals('utf8', $db->charset);
157+
}
158+
159+
//--------------------------------------------------------------------
160+
161+
public function testMagicGetMissing()
162+
{
163+
$db = new MockConnection($this->options);
164+
165+
$this->assertNull($db->foobar);
166+
}
131167
}

tests/system/Encryption/EncryptionTest.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ public function testKeyCreation()
7878
$this->assertEquals(16, strlen($this->encryption->createKey(16)));
7979
}
8080

81-
public function testBogusProperty()
82-
{
83-
$this->assertNull($this->encryption->bogus);
84-
}
85-
8681
// --------------------------------------------------------------------
8782

8883
public function testServiceSuccess()
@@ -129,4 +124,26 @@ public function testServiceShared()
129124
$this->assertEquals('anything', $encrypter->key);
130125
}
131126

127+
//--------------------------------------------------------------------
128+
129+
public function testMagicIssetTrue()
130+
{
131+
$this->assertTrue(isset($this->encryption->digest));
132+
}
133+
134+
public function testMagicIssetFalse()
135+
{
136+
$this->assertFalse(isset($this->encryption->bogus));
137+
}
138+
139+
public function testMagicGet()
140+
{
141+
$this->assertEquals('SHA512', $this->encryption->digest);
142+
}
143+
144+
public function testMagicGetMissing()
145+
{
146+
$this->assertNull($this->encryption->bogus);
147+
}
148+
132149
}

tests/system/I18n/TimeDifferenceTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,21 @@ public function testGetter()
200200
$this->assertNull($diff->nonsense);
201201
}
202202

203+
public function testMagicIssetTrue()
204+
{
205+
$current = Time::parse('March 10, 2017', 'America/Chicago');
206+
$diff = $current->difference('March 18, 2017', 'America/Chicago');
207+
208+
$this->assertTrue(isset($diff->days));
209+
$this->assertFalse(isset($diff->nonsense));
210+
}
211+
212+
public function testMagicIssetFalse()
213+
{
214+
$current = Time::parse('March 10, 2017', 'America/Chicago');
215+
$diff = $current->difference('March 18, 2017', 'America/Chicago');
216+
217+
$this->assertFalse(isset($diff->nonsense));
218+
}
219+
203220
}

tests/system/I18n/TimeTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,22 @@ public function testTestNow()
221221

222222
//--------------------------------------------------------------------
223223

224+
public function testMagicIssetTrue()
225+
{
226+
$time = Time::parse('January 1, 2016');
227+
228+
$this->assertTrue(isset($time->year));
229+
}
230+
231+
public function testMagicIssetFalse()
232+
{
233+
$time = Time::parse('January 1, 2016');
234+
235+
$this->assertFalse(isset($time->foobar));
236+
}
237+
238+
//--------------------------------------------------------------------
239+
224240
public function testGetYear()
225241
{
226242
$time = Time::parse('January 1, 2016');

tests/system/Session/SessionTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,26 @@ public function testHasReturnsFalseOnNotFound()
185185
$this->assertFalse($session->has('bar'));
186186
}
187187

188+
public function testIssetReturnsTrueOnSuccess()
189+
{
190+
$session = $this->getInstance();
191+
$session->start();
192+
193+
$_SESSION['foo'] = 'bar';
194+
195+
$this->assertTrue(isset($session->foo));
196+
}
197+
198+
public function testIssetReturnsFalseOnNotFound()
199+
{
200+
$session = $this->getInstance();
201+
$session->start();
202+
203+
$_SESSION['foo'] = 'bar';
204+
205+
$this->assertFalse(isset($session->bar));
206+
}
207+
188208
public function testPushNewValueIntoArraySessionValue()
189209
{
190210
$session = $this->getInstance();

0 commit comments

Comments
 (0)