@@ -24,46 +24,20 @@ public function test_eloquent_model(): void
24
24
25
25
$ timestamp = $ now ->format ('Y-m-d H:i:s ' );
26
26
27
- $ expected = <<<EOD
28
- Glhd\LaravelDumper\Tests\User {
29
- +"id": %d
30
- +"company_id": %d
31
-
32
- +"name": "Chris"
33
- +"created_at": " {$ timestamp }"
34
- +"updated_at": " {$ timestamp }"
35
- isDirty(): true
36
- +exists: true
37
- +wasRecentlyCreated: true
38
- #relations: array:1 [
39
- "company" => Glhd\LaravelDumper\Tests\Company {
40
- +"id": %d
41
- +"name": "Galahad"
42
- +"created_at": " {$ timestamp }"
43
- +"updated_at": " {$ timestamp }"
44
- isDirty(): false
45
- +exists: true
46
- +wasRecentlyCreated: true
47
- #relations: []
48
- …%d
49
- }
50
- ]
51
- #connection: "testing"
52
- #table: "users"
53
- #original: array:6 [
54
- "name" => "John"
55
-
56
- "company_id" => %d
57
- "updated_at" => " {$ timestamp }"
58
- "created_at" => " {$ timestamp }"
59
- "id" => %d
60
- ]
61
- #changes: []
62
- …%d
63
- }
64
- EOD ;
27
+ $ dump = $ this ->getDump ($ user );
65
28
66
- $ this ->assertDumpMatchesFormat ($ expected , $ user );
29
+ $ this ->assertStringStartsWith (User::class, $ dump );
30
+ $ this ->assertStringContainsString ('id ' , $ dump );
31
+ $ this ->assertStringContainsString ('company_id ' , $ dump );
32
+ $ this ->assertStringContainsString ('email ' , $ dump );
33
+ $ this ->assertStringContainsString ('name ' , $ dump );
34
+ $ this ->assertStringContainsString ('isDirty() ' , $ dump );
35
+ $ this ->assertStringContainsString ('exists ' , $ dump );
36
+ $ this ->assertStringContainsString ('wasRecentlyCreated ' , $ dump );
37
+ $ this ->assertStringContainsString ($ timestamp , $ dump );
38
+ $ this ->assertMatchesRegularExpression ('/\s*…\d+\n}$/ ' , $ dump );
39
+
40
+ $ this ->assertStringNotContainsString ('escapeWhenCastingToString ' , $ dump );
67
41
}
68
42
69
43
public function test_query_builder (): void
@@ -72,20 +46,12 @@ public function test_query_builder(): void
72
46
->
where (
'email ' ,
'[email protected] ' )
73
47
->limit (10 );
74
48
75
- $ expected = <<<EOD
76
- Illuminate\Database\Query\Builder {
77
- sql: "select * from "users" where "email" = '[email protected] ' limit 10"
78
- #connection: Illuminate\Database\SQLiteConnection {
79
- name: "testing"
80
- database: ":memory:"
81
- driver: "sqlite"
82
- …%d
83
- }
84
- …%d
85
- }
86
- EOD ;
87
-
88
- $ this ->assertDumpMatchesFormat ($ expected , $ builder );
49
+ $ dump = $ this ->getDump ($ builder );
50
+
51
+ $ this ->assertStringStartsWith ('Illuminate \\Database \\Query \\Builder { ' , $ dump );
52
+ $ this ->
assertStringContainsString (
'select * from "users" where "email" = \'[email protected] \' limit 10 ' ,
$ dump);
53
+ $ this ->assertStringContainsString ('#connection ' , $ dump );
54
+ $ this ->assertMatchesRegularExpression ('/\s*…\d+\n}$/ ' , $ dump );
89
55
}
90
56
91
57
/** @see https://github.com/glhd/laravel-dumper/issues/6 */
@@ -94,22 +60,14 @@ public function test_where_between_statement(): void
94
60
$ builder = User::where ('name ' , 'test ' )
95
61
->whereBetween ('id ' , [1 , 2 ]);
96
62
97
- $ expected = <<<EOD
98
- Illuminate\Database\Eloquent\Builder {
99
- sql: "select * from "users" where "name" = 'test' and "id" between '1' and '2'"
100
- #connection: Illuminate\Database\SQLiteConnection {
101
- name: "testing"
102
- database: ":memory:"
103
- driver: "sqlite"
104
- …%d
105
- }
106
- #model: Glhd\LaravelDumper\Tests\User { …}
107
- #eagerLoad: []
108
- …%d
109
- }
110
- EOD ;
63
+ $ dump = $ this ->getDump ($ builder );
111
64
112
- $ this ->assertDumpMatchesFormat ($ expected , $ builder );
65
+ $ this ->assertStringStartsWith ('Illuminate \\Database \\Eloquent \\Builder { ' , $ dump );
66
+ $ this ->assertStringContainsString ('select * from "users" where "name" = \'test \' and "id" between \'1 \' and \'2 \'' , $ dump );
67
+ $ this ->assertStringContainsString ('#connection ' , $ dump );
68
+ $ this ->assertStringContainsString ('#model ' , $ dump );
69
+ $ this ->assertStringContainsString (User::class, $ dump );
70
+ $ this ->assertMatchesRegularExpression ('/\s*…\d+\n}$/ ' , $ dump );
113
71
}
114
72
115
73
public function test_eloquent_builder (): void
@@ -133,116 +91,15 @@ public function test_eloquent_relation(): void
133
91
Company::create (['id ' => 1 , 'name ' => 'Galahad ' ]);
134
92
$ user = User::
create ([
'id ' =>
1 ,
'name ' =>
'John ' ,
'email ' =>
'[email protected] ' ,
'company_id ' =>
1 ]);
135
93
136
- $ expected = <<<EOD
137
- Illuminate\Database\Eloquent\Relations\BelongsTo {
138
- sql: "select * from "companies" where "companies"."id" = '1'"
139
- #connection: Illuminate\Database\SQLiteConnection {
140
- name: "testing"
141
- database: ":memory:"
142
- driver: "sqlite"
143
- …%d
144
- }
145
- #parent: Glhd\LaravelDumper\Tests\User { …}
146
- #related: Glhd\LaravelDumper\Tests\Company { …}
147
- …%d
148
- }
149
- EOD ;
94
+ $ dump = $ this ->getDump ($ user ->company ());
150
95
151
- $ this ->assertDumpMatchesFormat ($ expected , $ user ->company ());
152
- }
153
-
154
- public function test_unexpected_database_connections (): void
155
- {
156
- // Database connections don't necessarily need to have a $config
157
- // array. If they don't, we just return the original.
158
-
159
- $ conn = new class () implements ConnectionInterface {
160
- public $ foo = 'bar ' ;
161
-
162
- public function table ($ table , $ as = null )
163
- {
164
- }
165
-
166
- public function raw ($ value )
167
- {
168
- }
169
-
170
- public function selectOne ($ query , $ bindings = [], $ useReadPdo = true )
171
- {
172
- }
173
-
174
- public function select ($ query , $ bindings = [], $ useReadPdo = true )
175
- {
176
- }
177
-
178
- public function cursor ($ query , $ bindings = [], $ useReadPdo = true )
179
- {
180
- }
181
-
182
- public function insert ($ query , $ bindings = [])
183
- {
184
- }
185
-
186
- public function update ($ query , $ bindings = [])
187
- {
188
- }
189
-
190
- public function delete ($ query , $ bindings = [])
191
- {
192
- }
193
-
194
- public function statement ($ query , $ bindings = [])
195
- {
196
- }
197
-
198
- public function affectingStatement ($ query , $ bindings = [])
199
- {
200
- }
201
-
202
- public function unprepared ($ query )
203
- {
204
- }
205
-
206
- public function prepareBindings (array $ bindings )
207
- {
208
- }
209
-
210
- public function transaction (Closure $ callback , $ attempts = 1 )
211
- {
212
- }
213
-
214
- public function beginTransaction ()
215
- {
216
- }
217
-
218
- public function commit ()
219
- {
220
- }
221
-
222
- public function rollBack ()
223
- {
224
- }
225
-
226
- public function transactionLevel ()
227
- {
228
- }
229
-
230
- public function pretend (Closure $ callback )
231
- {
232
- }
233
-
234
- public function getDatabaseName ()
235
- {
236
- }
237
- };
238
-
239
- $ expected = <<<EOD
240
- Illuminate\Database\ConnectionInterface@anonymous {
241
- +foo: "bar"
242
- }
243
- EOD ;
244
-
245
- $ this ->assertDumpEquals ($ expected , $ conn );
96
+ $ this ->assertStringStartsWith ('Illuminate \\Database \\Eloquent \\Relations \\BelongsTo { ' , $ dump );
97
+ $ this ->assertStringContainsString ('select * from "companies" where "companies"."id" = \'1 \'' , $ dump );
98
+ $ this ->assertStringContainsString ('#parent ' , $ dump );
99
+ $ this ->assertStringContainsString ('#related ' , $ dump );
100
+ $ this ->assertStringContainsString (User::class, $ dump );
101
+ $ this ->assertStringContainsString (Company::class, $ dump );
102
+ $ this ->assertMatchesRegularExpression ('/\s*…\d+\n}$/ ' , $ dump );
246
103
}
247
104
248
105
protected function defineDatabaseMigrations ()
0 commit comments