Skip to content

Commit bd14253

Browse files
committed
Fix Config mock to properly handle offsetGet method calls in all test files
1 parent 7b1d360 commit bd14253

File tree

6 files changed

+163
-2
lines changed

6 files changed

+163
-2
lines changed

tests/Feature/NetopiaAesEncryptionTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,31 @@
4646
Config::shouldReceive('get')
4747
->withAnyArgs()
4848
->andReturnNull();
49+
50+
// Mock the array access methods (offsetGet, offsetExists, etc.)
51+
Config::shouldReceive('offsetGet')
52+
->withAnyArgs()
53+
->andReturnUsing(function ($key) {
54+
if ($key === 'netopia.signature') return TestHelper::getTestSignature();
55+
if ($key === 'netopia.public_key_path') return TestHelper::getTestPublicKeyPath();
56+
if ($key === 'netopia.private_key_path') return TestHelper::getTestPrivateKeyPath();
57+
if ($key === 'netopia.live_mode') return false;
58+
if ($key === 'netopia.default_currency') return 'RON';
59+
if ($key === 'logging.channels.deprecations') return ['driver' => 'null'];
60+
return null;
61+
});
62+
63+
Config::shouldReceive('offsetExists')
64+
->withAnyArgs()
65+
->andReturn(true);
66+
67+
Config::shouldReceive('offsetSet')
68+
->withAnyArgs()
69+
->andReturnNull();
70+
71+
Config::shouldReceive('offsetUnset')
72+
->withAnyArgs()
73+
->andReturnNull();
4974
});
5075

5176
it('can encrypt and decrypt data using AES-256-CBC', function () {

tests/Feature/NetopiaPaymentIntegrationTest.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,38 @@
7676
->withAnyArgs()
7777
->andReturn(null);
7878

79-
// Mock the Config array access
79+
// Mock the Config array access with comprehensive key handling
8080
Config::shouldReceive('offsetGet')
81+
->withAnyArgs()
8182
->andReturnUsing(function ($key) {
82-
if ($key === 'logging.default') return 'stack';
83+
if ($key === 'netopia.signature') return TestHelper::getTestSignature();
84+
if ($key === 'netopia.public_key_path') return TestHelper::getTestPublicKeyPath();
85+
if ($key === 'netopia.private_key_path') return TestHelper::getTestPrivateKeyPath();
86+
if ($key === 'netopia.live_mode') return false;
87+
if ($key === 'netopia.default_currency') return 'RON';
88+
if ($key === 'app.name') return 'Laravel Netopia Test';
89+
if ($key === 'app.debug') return true;
90+
if ($key === 'app.url') return 'http://localhost';
8391
if ($key === 'app.asset_url') return null;
92+
if ($key === 'logging.default') return 'stack';
93+
if ($key === 'logging.channels.stack') return ['driver' => 'stack', 'channels' => ['single']];
94+
if ($key === 'logging.channels.single') return ['driver' => 'single', 'path' => storage_path('logs/laravel.log')];
95+
if ($key === 'logging.channels.deprecations') return ['driver' => 'null'];
8496
return null;
8597
});
98+
99+
// Mock other array access methods
100+
Config::shouldReceive('offsetExists')
101+
->withAnyArgs()
102+
->andReturn(true);
103+
104+
Config::shouldReceive('offsetSet')
105+
->withAnyArgs()
106+
->andReturnNull();
107+
108+
Config::shouldReceive('offsetUnset')
109+
->withAnyArgs()
110+
->andReturnNull();
86111

87112
// Define test routes that the controller will redirect to
88113
Route::get('/payment/success', function () {

tests/Feature/NetopiaPaymentRedirectTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,31 @@
4646
Config::shouldReceive('get')
4747
->withAnyArgs()
4848
->andReturnNull();
49+
50+
// Mock the array access methods (offsetGet, offsetExists, etc.)
51+
Config::shouldReceive('offsetGet')
52+
->withAnyArgs()
53+
->andReturnUsing(function ($key) {
54+
if ($key === 'netopia.signature') return TestHelper::getTestSignature();
55+
if ($key === 'netopia.public_key_path') return TestHelper::getTestPublicKeyPath();
56+
if ($key === 'netopia.private_key_path') return TestHelper::getTestPrivateKeyPath();
57+
if ($key === 'netopia.live_mode') return false;
58+
if ($key === 'netopia.default_currency') return 'RON';
59+
if ($key === 'logging.channels.deprecations') return ['driver' => 'null'];
60+
return null;
61+
});
62+
63+
Config::shouldReceive('offsetExists')
64+
->withAnyArgs()
65+
->andReturn(true);
66+
67+
Config::shouldReceive('offsetSet')
68+
->withAnyArgs()
69+
->andReturnNull();
70+
71+
Config::shouldReceive('offsetUnset')
72+
->withAnyArgs()
73+
->andReturnNull();
4974
});
5075

5176
it('can generate a payment redirect URL for a 1.00 RON transaction', function () {

tests/Feature/NetopiaSandboxTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,31 @@
4242
Config::shouldReceive('get')
4343
->withAnyArgs()
4444
->andReturnNull();
45+
46+
// Mock the array access methods (offsetGet, offsetExists, etc.)
47+
Config::shouldReceive('offsetGet')
48+
->withAnyArgs()
49+
->andReturnUsing(function ($key) {
50+
if ($key === 'netopia.signature') return TestHelper::getTestSignature();
51+
if ($key === 'netopia.public_key_path') return TestHelper::getTestPublicKeyPath();
52+
if ($key === 'netopia.private_key_path') return TestHelper::getTestPrivateKeyPath();
53+
if ($key === 'netopia.live_mode') return false;
54+
if ($key === 'netopia.default_currency') return 'RON';
55+
if ($key === 'logging.channels.deprecations') return ['driver' => 'null'];
56+
return null;
57+
});
58+
59+
Config::shouldReceive('offsetExists')
60+
->withAnyArgs()
61+
->andReturn(true);
62+
63+
Config::shouldReceive('offsetSet')
64+
->withAnyArgs()
65+
->andReturnNull();
66+
67+
Config::shouldReceive('offsetUnset')
68+
->withAnyArgs()
69+
->andReturnNull();
4570
});
4671

4772
it('can generate payment form data for a 1.0 RON transaction', function () {

tests/Unit/NetopiaPaymentEncryptionTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,29 @@
3232
Config::shouldReceive('get')
3333
->withAnyArgs()
3434
->andReturnNull();
35+
36+
// Mock the array access methods (offsetGet, offsetExists, etc.)
37+
Config::shouldReceive('offsetGet')
38+
->withAnyArgs()
39+
->andReturnUsing(function ($key) {
40+
if ($key === 'netopia.signature') return TestHelper::getTestSignature();
41+
if ($key === 'netopia.public_key_path') return TestHelper::getTestPublicKeyPath();
42+
if ($key === 'netopia.private_key_path') return TestHelper::getTestPrivateKeyPath();
43+
if ($key === 'logging.channels.deprecations') return ['driver' => 'null'];
44+
return null;
45+
});
46+
47+
Config::shouldReceive('offsetExists')
48+
->withAnyArgs()
49+
->andReturn(true);
50+
51+
Config::shouldReceive('offsetSet')
52+
->withAnyArgs()
53+
->andReturnNull();
54+
55+
Config::shouldReceive('offsetUnset')
56+
->withAnyArgs()
57+
->andReturnNull();
3558
});
3659

3760
it('can encrypt data using the signature and public key', function () {

tests/Unit/NetopiaPaymentHelperTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,44 @@
2020
Config::shouldReceive('get')
2121
->with('netopia.private_key_path')
2222
->andReturn(TestHelper::getTestPrivateKeyPath());
23+
24+
// Mock additional Config calls that might be needed in GitHub Actions
25+
Config::shouldReceive('get')
26+
->with('logging.channels.deprecations')
27+
->andReturn(['driver' => 'null']);
28+
29+
// Allow Config::set calls
30+
Config::shouldReceive('set')
31+
->withAnyArgs()
32+
->andReturnNull();
33+
34+
// Catch-all for any other config calls
35+
Config::shouldReceive('get')
36+
->withAnyArgs()
37+
->andReturnNull();
38+
39+
// Mock the array access methods (offsetGet, offsetExists, etc.)
40+
Config::shouldReceive('offsetGet')
41+
->withAnyArgs()
42+
->andReturnUsing(function ($key) {
43+
if ($key === 'netopia.signature') return TestHelper::getTestSignature();
44+
if ($key === 'netopia.public_key_path') return TestHelper::getTestPublicKeyPath();
45+
if ($key === 'netopia.private_key_path') return TestHelper::getTestPrivateKeyPath();
46+
if ($key === 'logging.channels.deprecations') return ['driver' => 'null'];
47+
return null;
48+
});
49+
50+
Config::shouldReceive('offsetExists')
51+
->withAnyArgs()
52+
->andReturn(true);
53+
54+
Config::shouldReceive('offsetSet')
55+
->withAnyArgs()
56+
->andReturnNull();
57+
58+
Config::shouldReceive('offsetUnset')
59+
->withAnyArgs()
60+
->andReturnNull();
2361
});
2462

2563
it('can generate payment form data for a request', function () {

0 commit comments

Comments
 (0)