Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit 491c9c2

Browse files
Merge pull request #5 from Mastercard/feature/fixing-code-smells
Add test coverage for __construct methods
2 parents 5a01270 + 322a2e1 commit 491c9c2

File tree

8 files changed

+71
-11
lines changed

8 files changed

+71
-11
lines changed

src/Developer/Encryption/FieldLevelEncryption.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*/
1313
class FieldLevelEncryption {
1414

15-
//NOSONAR
1615
private function __construct() {
1716
// This class can't be instantiated
1817
}

src/Developer/Json/JsonPath.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class JsonPath {
1616
const FIRST_CHILD_KEY = "/(?:\[')([^\[\]]*)(?:'\])/"; // Returns "obj1" for "$['obj1']['obj2']"
1717
const FIRST_TOKEN_IN_PATH = "/(\['[^\[\]]*'\])/"; // Returns "['obj1']" for "$['obj1']['obj2']"
1818

19-
//NOSONAR
2019
private function __construct() {
2120
// This class can't be instantiated
2221
}

src/Developer/Utils/EncodingUtils.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
class EncodingUtils {
77

8-
//NOSONAR
98
private function __construct() {
109
// This class can't be instantiated
1110
}

src/Developer/Utils/EncryptionUtils.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class EncryptionUtils {
1414
const PKCS_8_PEM_HEADER = '-----BEGIN PRIVATE KEY-----';
1515
const PKCS_8_PEM_FOOTER = '-----END PRIVATE KEY-----';
1616

17-
//NOSONAR
1817
private function __construct() {
1918
// This class can't be instantiated
2019
}

tests/Developer/Encryption/FieldLevelEncryptionTest.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@
99

1010
class FieldLevelEncryptionTest extends TestCase {
1111

12+
public function testConstruct_ShouldBePrivate() {
13+
// GIVEN
14+
$class = new ReflectionClass('Mastercard\Developer\Encryption\FieldLevelEncryption');
15+
$constructor = $class->getConstructor();
16+
17+
// WHEN
18+
$isPrivate = $constructor->isPrivate();
19+
20+
// THEN
21+
$this->assertTrue($isPrivate);
22+
23+
// COVERAGE
24+
$constructor->setAccessible(true);
25+
$constructor->invoke($class->newInstanceWithoutConstructor());
26+
}
27+
1228
private static function callEncryptBytes($params) {
1329
return TestUtils::callPrivateStatic('\FieldLevelEncryption', 'encryptBytes', $params);
1430
}
@@ -53,7 +69,7 @@ public function testDecryptBytes_InteroperabilityTest() {
5369
}
5470

5571
public function testDecryptPayload_InteroperabilityTest() {
56-
72+
5773
// GIVEN
5874
$encryptedPayload = '{"data":"WtBPYHL5jdU/BsECYzlyRUPIElWCwSCgKhk5RPy2AMZBGmC8OUJ1L9HC/SF2QpCU+ucZTmo7XOjhSdVi0/yrdZP1OG7dVWcW4MEWpxiU1gl0fS0LKKPOFjEymSP5f5otdTFCp00xPfzp+l6K3S3kZTAuSG1gh6TaRL+qfC1POz8KxhCEL8D1MDvxnlmchPx/hEyAzav0AID3T7T4WomzUXErNrnbDCCiL6pm4IBR8cDAzU4eSmTxdzZFyvTpBQDXVyFdkaNTo3GXk837wujVK8EX3c+gsJvMq4XVJFwGmPNhPM6P7OmdK45cldWrD5j2gO2VBH5aW1EXfot7d11bjJC9T8D/ZOQFF6uLIG7J9x9R0Ts0zXD/H24y9/jF30rKKX7TNmKHn5uh1Czd+h7ryIAqaQsOu6ILBKfH7W/NIR5qYN1GiL/kOYwx2pdIGQdcdolVdxV8Z6bt4Tcvq3jSZaCbhJI/kphZL7QHJgcG6luz9k0457x/0QCDPlve6JNgUQzAOYC64X0a07JpERH0O08/YbntKEq6qf7UhloyI5A="}';
5975
$config = TestUtils::getTestFieldLevelEncryptionConfigBuilder()
@@ -65,11 +81,11 @@ public function testDecryptPayload_InteroperabilityTest() {
6581
$oaepPaddingDigest = 'SHA256';
6682
$encryptedKey = 'dobCRy+NUxdQdN0oMLT4dXUzQ+We7BahMfJunoAmwwUpk9jJrW66BASPalS2QWChPaKDM4Ft/BeNsu0wBoUZ0hHIT9ftx5g4tY6Xu2iLRiFWFDCHYOSdL+yVv98FcM6fxc34FNyg3/rOPWeyS3Q9YAOgcqiCwWYu4kqa34tNWCW1vnTmtz+dCKiiCZo/uHUkCtoAI5fEe+inHHToZL+LFlQ2Xd0u/nsu5Ep14Il5mTv8FyfLgwRgfilcqy4t2Kh3bpZ46LllO36DHXtQoI1e0ayMFfKTO87++NWxYNOilrverJ01WHnA+PyXhg4XU3RlU0CVWBN06fKbHBDH6GCmOA==';
6783
$iv = '+yBXlo+gYGe2q0xzLDLLzQ==';
68-
84+
6985
// WHEN
7086
$params = new FieldLevelEncryptionParams($config, $iv, $encryptedKey, $oaepPaddingDigest);
7187
$payload = FieldLevelEncryption::decryptPayload($encryptedPayload, $config, $params);
72-
88+
7389
// THEN
7490
$this->assertTrue(StringUtils::contains($payload, 'account'));
7591
}

tests/Developer/Json/JsonPathTest.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@
55

66
class JsonPathTest extends TestCase {
77

8+
public function testConstruct_ShouldBePrivate() {
9+
// GIVEN
10+
$class = new ReflectionClass('Mastercard\Developer\Json\JsonPath');
11+
$constructor = $class->getConstructor();
12+
13+
// WHEN
14+
$isPrivate = $constructor->isPrivate();
15+
16+
// THEN
17+
$this->assertTrue($isPrivate);
18+
19+
// COVERAGE
20+
$constructor->setAccessible(true);
21+
$constructor->invoke($class->newInstanceWithoutConstructor());
22+
}
23+
824
public function testNormalizePath() {
925

1026
// GIVEN
@@ -59,7 +75,7 @@ public function testNormalizePath_ShouldThrowInvalidArgumentException_WhenJsonPa
5975
}
6076

6177
public function testGetElementKey() {
62-
78+
6379
// GIVEN
6480
$jsonPath1 = '$[\'obj0\'][\'obj1\'][\'obj2\']';
6581
$jsonPath2 = 'obj1.obj2';
@@ -220,7 +236,7 @@ public function testGetElementKey_ShouldThrowInvalidArgumentException_WhenJsonPa
220236
}
221237

222238
public function testGetParentPath_ShouldThrowInvalidArgumentException_WhenNoParent() {
223-
239+
224240
// GIVEN
225241
$jsonPath = '$';
226242

@@ -233,7 +249,7 @@ public function testGetParentPath_ShouldThrowInvalidArgumentException_WhenNoPare
233249
}
234250

235251
public function testGetElementKey_ShouldThrowInvalidArgumentException_WhenNoKey() {
236-
252+
237253
// GIVEN
238254
$jsonPath = '$';
239255

tests/Developer/Utils/EncodingUtilsTest.php

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

77
class EncodingUtilsTest extends TestCase {
88

9+
public function testConstruct_ShouldBePrivate() {
10+
// GIVEN
11+
$class = new ReflectionClass('Mastercard\Developer\Utils\EncodingUtils');
12+
$constructor = $class->getConstructor();
13+
14+
// WHEN
15+
$isPrivate = $constructor->isPrivate();
16+
17+
// THEN
18+
$this->assertTrue($isPrivate);
19+
20+
// COVERAGE
21+
$constructor->setAccessible(true);
22+
$constructor->invoke($class->newInstanceWithoutConstructor());
23+
}
24+
925
public function testHexEncode() {
1026
$this->assertEquals('00', EncodingUtils::hexEncode("\0"));
1127
$this->assertEquals('736f6d652064617461', EncodingUtils::hexEncode('some data'));
@@ -41,4 +57,4 @@ public function testHexDecode_ShouldThrowInvalidArgumentException_WhenNullValue(
4157
$this->expectExceptionMessage('Can\'t hex decode an empty value!');
4258
EncodingUtils::hexDecode(null);
4359
}
44-
}
60+
}

tests/Developer/Utils/EncryptionUtilsTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@
55

66
class EncryptionUtilsTest extends TestCase {
77

8+
public function testConstruct_ShouldBePrivate() {
9+
// GIVEN
10+
$class = new ReflectionClass('Mastercard\Developer\Utils\EncryptionUtils');
11+
$constructor = $class->getConstructor();
12+
13+
// WHEN
14+
$isPrivate = $constructor->isPrivate();
15+
16+
// THEN
17+
$this->assertTrue($isPrivate);
18+
19+
// COVERAGE
20+
$constructor->setAccessible(true);
21+
$constructor->invoke($class->newInstanceWithoutConstructor());
22+
}
23+
824
public function testLoadEncryptionCertificate_ShouldSupportPem() {
925

1026
// GIVEN

0 commit comments

Comments
 (0)