Skip to content

Commit 027381d

Browse files
committed
chore: fix example test code for starter and module
1 parent 052817b commit 027381d

4 files changed

Lines changed: 21 additions & 18 deletions

File tree

admin/module/tests/database/ExampleDatabaseTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<?php
22

3+
use CodeIgniter\Test\CIUnitTestCase;
4+
use CodeIgniter\Test\DatabaseTestTrait;
5+
use Tests\Support\Database\Seeds\ExampleSeeder;
36
use Tests\Support\Models\ExampleModel;
47

58
/**
69
* @internal
710
*/
8-
final class ExampleDatabaseTest extends \Tests\Support\DatabaseTestCase
11+
final class ExampleDatabaseTest extends CIUnitTestCase
912
{
10-
protected function setUp(): void
11-
{
12-
parent::setUp();
13+
use DatabaseTestTrait;
1314

14-
// Extra code to run before each test
15-
}
15+
protected $seed = ExampleSeeder::class;
1616

1717
public function testModelFindAll()
1818
{
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
<?php
22

3+
use CodeIgniter\Test\CIUnitTestCase;
4+
use Config\Services;
5+
36
/**
47
* @internal
58
*/
6-
final class ExampleSessionTest extends \Tests\Support\SessionTestCase
9+
final class ExampleSessionTest extends CIUnitTestCase
710
{
8-
protected function setUp(): void
9-
{
10-
parent::setUp();
11-
}
12-
1311
public function testSessionSimple()
1412
{
15-
$this->session->set('logged_in', 123);
16-
17-
$value = $this->session->get('logged_in');
13+
$session = Services::session();
1814

19-
$this->assertSame(123, $value);
15+
$session->set('logged_in', 123);
16+
$this->assertSame(123, $session->get('logged_in'));
2017
}
2118
}

admin/starter/tests/database/ExampleDatabaseTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use CodeIgniter\Test\CIUnitTestCase;
44
use CodeIgniter\Test\DatabaseTestTrait;
5+
use Tests\Support\Database\Seeds\ExampleSeeder;
56
use Tests\Support\Models\ExampleModel;
67

78
/**
@@ -11,6 +12,8 @@ final class ExampleDatabaseTest extends CIUnitTestCase
1112
{
1213
use DatabaseTestTrait;
1314

15+
protected $seed = ExampleSeeder::class;
16+
1417
public function testModelFindAll()
1518
{
1619
$model = new ExampleModel();
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use CodeIgniter\Test\CIUnitTestCase;
4+
use Config\Services;
45

56
/**
67
* @internal
@@ -9,7 +10,9 @@ final class ExampleSessionTest extends CIUnitTestCase
910
{
1011
public function testSessionSimple()
1112
{
12-
$this->session->set('logged_in', 123);
13-
$this->assertSame(123, $this->session->get('logged_in'));
13+
$session = Services::session();
14+
15+
$session->set('logged_in', 123);
16+
$this->assertSame(123, $session->get('logged_in'));
1417
}
1518
}

0 commit comments

Comments
 (0)