Skip to content

Commit 0ed774b

Browse files
committed
Convert unittests to PHP 8 attributes
1 parent d583956 commit 0ed774b

File tree

61 files changed

+837
-821
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+837
-821
lines changed

src/test/php/rdbms/unittest/ConfiguredConnectionManagerTest.class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use io\streams\MemoryInputStream;
44
use rdbms\ConnectionManager;
5+
use rdbms\unittest\mock\RegisterMockConnection;
56
use util\Properties;
67

78
/**
@@ -10,7 +11,7 @@
1011
* @see xp://rdbms.ConnectionManager#configure
1112
* @see xp://net.xp_framework.unittest.rdbms.ConnectionManagerTest
1213
*/
13-
#[@action(new \rdbms\unittest\mock\RegisterMockConnection())]
14+
#[Action(eval: 'new RegisterMockConnection()')]
1415
class ConfiguredConnectionManagerTest extends ConnectionManagerTest {
1516

1617
/**

src/test/php/rdbms/unittest/ConnectionManagerTest.class.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php namespace rdbms\unittest;
22

33
use rdbms\{ConnectionManager, ConnectionNotRegisteredException, DBConnection, DriverNotSupportedException};
4-
use unittest\TestCase;
4+
use unittest\{Expect, Test, TestCase};
55

66
/**
77
* ConnectionManager testcase
@@ -25,53 +25,53 @@ public function setUp() {
2525
*/
2626
protected abstract function instanceWith($dsns);
2727

28-
#[@test]
28+
#[Test]
2929
public function initallyEmpty() {
3030
$this->assertEquals([], $this->instanceWith([])->getConnections());
3131
}
3232

33-
#[@test]
33+
#[Test]
3434
public function acquireExistingConnectionViaGetByHost() {
3535
$cm= $this->instanceWith(['mydb' => 'mock://user:pass@host/db?autoconnect=1']);
3636
$this->assertInstanceOf(DBConnection::class, $cm->getByHost('mydb', 0));
3737
}
3838

39-
#[@test, @expect(ConnectionNotRegisteredException::class)]
39+
#[Test, Expect(ConnectionNotRegisteredException::class)]
4040
public function acquireNonExistantConnectionViaGetByHost() {
4141
$cm= $this->instanceWith(['mydb' => 'mock://user:pass@host/db?autoconnect=1']);
4242
$cm->getByHost('nonexistant', 0);
4343
}
4444

45-
#[@test]
45+
#[Test]
4646
public function acquireExistingConnectionViaGet() {
4747
$cm= $this->instanceWith(['mydb' => 'mock://user:pass@host/db?autoconnect=1']);
4848
$this->assertInstanceOf(DBConnection::class, $cm->getByHost('mydb', 0));
4949
}
5050

51-
#[@test, @expect(ConnectionNotRegisteredException::class)]
51+
#[Test, Expect(ConnectionNotRegisteredException::class)]
5252
public function acquireNonExistantConnectionWithExistantUserViaGet() {
5353
$cm= $this->instanceWith(['mydb' => 'mock://user:pass@host/db?autoconnect=1']);
5454
$cm->get('nonexistant', 'user');
5555
}
5656

57-
#[@test, @expect(ConnectionNotRegisteredException::class)]
57+
#[Test, Expect(ConnectionNotRegisteredException::class)]
5858
public function acquireExistantConnectionWithNonExistantUserViaGet() {
5959
$cm= $this->instanceWith(['mydb' => 'mock://user:pass@host/db?autoconnect=1']);
6060
$cm->get('mydb', 'nonexistant');
6161
}
6262

63-
#[@test]
63+
#[Test]
6464
public function invalidDsnScheme() {
6565
$this->instanceWith(['mydb' => 'invalid://user:pass@host/db?autoconnect=1']);
6666
}
6767

68-
#[@test, @expect(DriverNotSupportedException::class)]
68+
#[Test, Expect(DriverNotSupportedException::class)]
6969
public function acquireInvalidDsnScheme() {
7070
$cm= $this->instanceWith(['mydb' => 'invalid://user:pass@host/db?autoconnect=1']);
7171
$cm->getByHost('mydb', 0);
7272
}
7373

74-
#[@test]
74+
#[Test]
7575
public function getByUserAndHost() {
7676
$dsns= [
7777
'mydb.user' => 'mock://user:pass@host/db?autoconnect=1',
@@ -81,7 +81,7 @@ public function getByUserAndHost() {
8181
$this->assertEquals(new \rdbms\DSN($dsns['mydb.user']), $cm->get('mydb', 'user')->dsn);
8282
}
8383

84-
#[@test]
84+
#[Test]
8585
public function getFirstByHost() {
8686
$dsns= [
8787
'mydb.user' => 'mock://user:pass@host/db?autoconnect=1',
@@ -91,7 +91,7 @@ public function getFirstByHost() {
9191
$this->assertEquals(new \rdbms\DSN($dsns['mydb.user']), $cm->getByHost('mydb', 0)->dsn);
9292
}
9393

94-
#[@test]
94+
#[Test]
9595
public function getSecondByHost() {
9696
$dsns= [
9797
'mydb.user' => 'mock://user:pass@host/db?autoconnect=1',
@@ -101,7 +101,7 @@ public function getSecondByHost() {
101101
$this->assertEquals(new \rdbms\DSN($dsns['mydb.admin']), $cm->getByHost('mydb', 1)->dsn);
102102
}
103103

104-
#[@test]
104+
#[Test]
105105
public function getAllByHost() {
106106
$dsns= [
107107
'mydb.user' => 'mock://user:pass@host/db?autoconnect=1',

src/test/php/rdbms/unittest/CriteriaTest.class.php

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<?php namespace rdbms\unittest;
22

33
use lang\IllegalArgumentException;
4-
use rdbms\{Criteria, DriverManager, SQLStateException};
54
use rdbms\criterion\Restrictions;
65
use rdbms\unittest\dataset\Job;
7-
use unittest\TestCase;
6+
use rdbms\unittest\mock\RegisterMockConnection;
7+
use rdbms\{Criteria, DriverManager, SQLStateException};
8+
use unittest\{Expect, Test, TestCase};
89

910
/**
1011
* Test criteria class
1112
*
1213
* @see xp://rdbms.Criteria
1314
*/
14-
#[@action(new \rdbms\unittest\mock\RegisterMockConnection())]
15+
#[Action(eval: 'new RegisterMockConnection()')]
1516
class CriteriaTest extends TestCase {
1617
public $conn= null;
1718
public $peer= null;
@@ -37,23 +38,23 @@ protected function assertSql($sql, $criteria) {
3738
$this->assertEquals($sql, trim($criteria->toSQL($this->conn, $this->peer), ' '));
3839
}
3940

40-
#[@test]
41+
#[Test]
4142
public function emptyCriteria() {
4243
$this->assertSql('', new Criteria());
4344
}
4445

45-
#[@test]
46+
#[Test]
4647
public function simpleCriteria() {
4748
$this->assertSql('where job_id = 1', new Criteria(['job_id', 1, EQUAL]));
4849
}
4950

50-
#[@test, @expect(IllegalArgumentException::class)]
51+
#[Test, Expect(IllegalArgumentException::class)]
5152
public function nonExistantFieldCausesException() {
5253
$criteria= new Criteria(['non-existant-field', 1, EQUAL]);
5354
$criteria->toSQL($this->conn, $this->peer);
5455
}
5556

56-
#[@test]
57+
#[Test]
5758
public function complexCriteria() {
5859
with ($c= new Criteria()); {
5960
$c->add('job_id', 1, EQUAL);
@@ -68,87 +69,87 @@ public function complexCriteria() {
6869
);
6970
}
7071

71-
#[@test]
72+
#[Test]
7273
public function inCriteria() {
7374
$c= new Criteria();
7475
$c->add('job_id', [1, 2], IN);
7576

7677
$this->assertSql('where job_id in (1, 2)', $c);
7778
}
7879

79-
#[@test]
80+
#[Test]
8081
public function notInCriteria() {
8182
$c= new Criteria();
8283
$c->add('job_id', [1, 2], NOT_IN);
8384

8485
$this->assertSql('where job_id not in (1, 2)', $c);
8586
}
8687

87-
#[@test]
88+
#[Test]
8889
public function likeCriteria() {
8990
$c= new Criteria();
9091
$c->add('title', '%keyword%', LIKE);
9192

9293
$this->assertSql('where title like "%keyword%"', $c);
9394
}
9495

95-
#[@test]
96+
#[Test]
9697
public function equalCriteria() {
9798
$c= new Criteria();
9899
$c->add('job_id', 1, EQUAL);
99100

100101
$this->assertSql('where job_id = 1', $c);
101102
}
102103

103-
#[@test]
104+
#[Test]
104105
public function notEqualCriteria() {
105106
$c= new Criteria();
106107
$c->add('job_id', 1, NOT_EQUAL);
107108

108109
$this->assertSql('where job_id != 1', $c);
109110
}
110111

111-
#[@test]
112+
#[Test]
112113
public function lessThanCriteria() {
113114
$c= new Criteria();
114115
$c->add('job_id', 100, LESS_THAN);
115116

116117
$this->assertSql('where job_id < 100', $c);
117118
}
118119

119-
#[@test]
120+
#[Test]
120121
public function greaterThanCriteria() {
121122
$c= new Criteria();
122123
$c->add('job_id', 100, GREATER_THAN);
123124

124125
$this->assertSql('where job_id > 100', $c);
125126
}
126127

127-
#[@test]
128+
#[Test]
128129
public function lessEqualCriteria() {
129130
$c= new Criteria();
130131
$c->add('job_id', 100, LESS_EQUAL);
131132

132133
$this->assertSql('where job_id <= 100', $c);
133134
}
134135

135-
#[@test]
136+
#[Test]
136137
public function greaterEqualCriteria() {
137138
$c= new Criteria();
138139
$c->add('job_id', 100, GREATER_EQUAL);
139140

140141
$this->assertSql('where job_id >= 100', $c);
141142
}
142143

143-
#[@test]
144+
#[Test]
144145
public function bitAndCriteria() {
145146
$c= new Criteria();
146147
$c->add('job_id', 100, BIT_AND);
147148

148149
$this->assertSql('where job_id & 100 != 0', $c);
149150
}
150151

151-
#[@test]
152+
#[Test]
152153
public function restrictionsFactory() {
153154
$job_id= Job::column('job_id');
154155
$c= new Criteria(Restrictions::anyOf(
@@ -173,30 +174,30 @@ public function restrictionsFactory() {
173174
);
174175
}
175176

176-
#[@test]
177+
#[Test]
177178
public function constructorAcceptsVarArgArrays() {
178179
$this->assertSql(
179180
'where job_id = 1 and title = "Hello"',
180181
new Criteria(['job_id', 1, EQUAL], ['title', 'Hello', EQUAL])
181182
);
182183
}
183184

184-
#[@test]
185+
#[Test]
185186
public function addReturnsThis() {
186187
$this->assertInstanceOf(Criteria::class, (new Criteria())->add('job_id', 1, EQUAL));
187188
}
188189

189-
#[@test]
190+
#[Test]
190191
public function addOrderByReturnsThis() {
191192
$this->assertInstanceOf(Criteria::class, (new Criteria())->add('job_id', 1, EQUAL)->addOrderBy('valid_from', DESCENDING));
192193
}
193194

194-
#[@test]
195+
#[Test]
195196
public function addGroupByReturnsThis() {
196197
$this->assertInstanceOf(Criteria::class, (new Criteria())->add('job_id', 1, EQUAL)->addGroupBy('valid_from'));
197198
}
198199

199-
#[@test]
200+
#[Test]
200201
public function addOrderByColumn() {
201202
with ($c= new Criteria()); {
202203
$c->addOrderBy(Job::column('valid_from'));
@@ -208,7 +209,7 @@ public function addOrderByColumn() {
208209
);
209210
}
210211

211-
#[@test]
212+
#[Test]
212213
public function addOrderByString() {
213214
with ($c= new Criteria()); {
214215
$c->addOrderBy("valid_from");
@@ -220,7 +221,7 @@ public function addOrderByString() {
220221
);
221222
}
222223

223-
#[@test]
224+
#[Test]
224225
public function addGroupByColumn() {
225226
with ($c= new Criteria()); {
226227
$c->addGroupBy(Job::column('valid_from'));
@@ -232,7 +233,7 @@ public function addGroupByColumn() {
232233
);
233234
}
234235

235-
#[@test]
236+
#[Test]
236237
public function addGroupByString() {
237238
with ($c= new Criteria()); {
238239
$c->addGroupBy("valid_from");
@@ -244,22 +245,22 @@ public function addGroupByString() {
244245
);
245246
}
246247

247-
#[@test, @expect(IllegalArgumentException::class)]
248+
#[Test, Expect(IllegalArgumentException::class)]
248249
public function createNonExistantColumn() {
249250
Job::column('not_existant');
250251
}
251252

252-
#[@test, @expect(SQLStateException::class)]
253+
#[Test, Expect(SQLStateException::class)]
253254
public function addGroupByNonExistantColumnString() {
254255
(new Criteria())->addGroupBy('not_existant')->toSQL($this->conn, $this->peer);
255256
}
256257

257-
#[@test]
258+
#[Test]
258259
public function fetchModeChaining() {
259260
$this->assertInstanceOf(Criteria::class, (new Criteria())->setFetchmode(\rdbms\join\Fetchmode::join('PersonJob')));
260261
}
261262

262-
#[@test]
263+
#[Test]
263264
public function testIsJoin() {
264265
$crit= new Criteria();
265266
$this->assertFalse($crit->isJoin());
@@ -269,7 +270,7 @@ public function testIsJoin() {
269270
$this->assertFalse($crit->setFetchmode(\rdbms\join\Fetchmode::select('PersonJob'))->isJoin());
270271
}
271272

272-
#[@test]
273+
#[Test]
273274
public function testJoinWithoutCondition() {
274275
$jp= new \rdbms\join\JoinProcessor(Job::getPeer());
275276
$jp->setFetchModes(['PersonJob->Department' => 'join']);
@@ -283,7 +284,7 @@ public function testJoinWithoutCondition() {
283284
$jp->leaveJoinContext();
284285
}
285286

286-
#[@test]
287+
#[Test]
287288
public function testJoinWithCondition() {
288289
$jp= new \rdbms\join\JoinProcessor(Job::getPeer());
289290
$jp->setFetchModes(['PersonJob->Department' => 'join']);
@@ -299,7 +300,7 @@ public function testJoinWithCondition() {
299300
$jp->leaveJoinContext();
300301
}
301302

302-
#[@test]
303+
#[Test]
303304
public function testJoinWithProjection() {
304305
$jp= new \rdbms\join\JoinProcessor(Job::getPeer());
305306
$jp->setFetchModes(['PersonJob->Department' => 'join']);

0 commit comments

Comments
 (0)