@@ -13,21 +13,21 @@ class PlivoHandlerTest extends TestCase
13
13
private $ res ;
14
14
/** @var PlivoHandler */
15
15
private $ handler ;
16
-
16
+
17
17
public function testCanBeInstantiatedAndProvidesDefaultFormatter ()
18
18
{
19
19
$ handler = new PlivoHandler ('token ' , 'auth_id ' , '+15555555555 ' , '+16666666666 ' );
20
20
21
21
$ this ->assertInstanceOf ('Tylercd100 \\Monolog \\Formatter \\SMSFormatter ' , $ handler ->getFormatter ());
22
- $ this ->assertAttributeEquals ('token ' , 'authToken ' , $ handler );
23
- $ this ->assertAttributeEquals ('auth_id ' , 'authId ' , $ handler );
24
- $ this ->assertAttributeEquals ('+15555555555 ' , 'fromNumber ' , $ handler );
25
- $ this ->assertAttributeEquals ('+16666666666 ' , 'toNumber ' , $ handler );
22
+ $ this ->assertEquals ('token ' , $ this -> accessProtected ( $ handler , 'authToken ' ) );
23
+ $ this ->assertEquals ('auth_id ' , $ this -> accessProtected ( $ handler , 'authId ' ) );
24
+ $ this ->assertEquals ('+15555555555 ' , $ this -> accessProtected ( $ handler , 'fromNumber ' ) );
25
+ $ this ->assertEquals ('+16666666666 ' , $ this -> accessProtected ( $ handler , 'toNumber ' ) );
26
26
}
27
27
28
28
public function testItThrowsExceptionWhenUsingDifferentVersionOtherThanV1 ()
29
29
{
30
- $ this ->setExpectedException (Exception::class);
30
+ $ this ->expectException (Exception::class);
31
31
$ handler = new PlivoHandler ('token ' , 'auth_id ' , '+15555555555 ' , '+16666666666 ' , Logger::CRITICAL , true , true , 'plivo.foo.bar ' , 'v2 ' );
32
32
}
33
33
@@ -38,7 +38,7 @@ public function testWriteHeader()
38
38
fseek ($ this ->res , 0 );
39
39
$ content = fread ($ this ->res , 1024 );
40
40
41
- $ this ->assertRegexp ('/POST \/v1\/Account\/auth_id\/Message\/ HTTP\/1.1 \\r \\nHost: api.plivo.com \\r \\nAuthorization: Basic YXV0aF9pZDp0b2tlbg== \\r \\nContent-Type: application\/json \\r \\nContent-Length: \d{2,4} \\r \\n \\r \\n/ ' , $ content );
41
+ $ this ->assertMatchesRegularExpression ('/POST \/v1\/Account\/auth_id\/Message\/ HTTP\/1.1 \\r \\nHost: api.plivo.com \\r \\nAuthorization: Basic YXV0aF9pZDp0b2tlbg== \\r \\nContent-Type: application\/json \\r \\nContent-Length: \d{2,4} \\r \\n \\r \\n/ ' , $ content );
42
42
43
43
return $ content ;
44
44
}
@@ -50,7 +50,7 @@ public function testWriteCustomHostHeader()
50
50
fseek ($ this ->res , 0 );
51
51
$ content = fread ($ this ->res , 1024 );
52
52
53
- $ this ->assertRegexp ('/POST \/v1\/Account\/auth_id\/Message\/ HTTP\/1.1 \\r \\nHost: plivo.foo.bar \\r \\nAuthorization: Basic YXV0aF9pZDp0b2tlbg== \\r \\nContent-Type: application\/json \\r \\nContent-Length: \d{2,4} \\r \\n \\r \\n/ ' , $ content );
53
+ $ this ->assertMatchesRegularExpression ('/POST \/v1\/Account\/auth_id\/Message\/ HTTP\/1.1 \\r \\nHost: plivo.foo.bar \\r \\nAuthorization: Basic YXV0aF9pZDp0b2tlbg== \\r \\nContent-Type: application\/json \\r \\nContent-Length: \d{2,4} \\r \\n \\r \\n/ ' , $ content );
54
54
55
55
return $ content ;
56
56
}
@@ -60,7 +60,7 @@ public function testWriteCustomHostHeader()
60
60
*/
61
61
public function testWriteContent ($ content )
62
62
{
63
- $ this ->assertRegexp ('/{"src":"\+15555555555","dst":"\+16666666666","text":"test1"}/ ' , $ content );
63
+ $ this ->assertMatchesRegularExpression ('/{"src":"\+15555555555","dst":"\+16666666666","text":"test1"}/ ' , $ content );
64
64
}
65
65
66
66
public function testWriteContentV1WithoutToAndFromNumbers ()
@@ -70,7 +70,7 @@ public function testWriteContentV1WithoutToAndFromNumbers()
70
70
fseek ($ this ->res , 0 );
71
71
$ content = fread ($ this ->res , 1024 );
72
72
73
- $ this ->assertRegexp ('/{"src":false,"dst":null,"text":"test1"}/ ' , $ content );
73
+ $ this ->assertMatchesRegularExpression ('/{"src":false,"dst":null,"text":"test1"}/ ' , $ content );
74
74
75
75
return $ content ;
76
76
}
@@ -80,7 +80,7 @@ public function testWriteContentV1WithoutToAndFromNumbers()
80
80
*/
81
81
public function testWriteContentNotify ($ content )
82
82
{
83
- $ this ->assertRegexp ('/{"src":"\+15555555555","dst":"\+16666666666","text":"test1"}/ ' , $ content );
83
+ $ this ->assertMatchesRegularExpression ('/{"src":"\+15555555555","dst":"\+16666666666","text":"test1"}/ ' , $ content );
84
84
}
85
85
86
86
public function testWriteWithComplexMessage ()
@@ -90,18 +90,17 @@ public function testWriteWithComplexMessage()
90
90
fseek ($ this ->res , 0 );
91
91
$ content = fread ($ this ->res , 1024 );
92
92
93
- $ this ->assertRegexp ('/{"src":"\+15555555555","dst":"\+16666666666","text":"Backup of database example finished in 16 minutes\."}/ ' , $ content );
93
+ $ this ->assertMatchesRegularExpression ('/{"src":"\+15555555555","dst":"\+16666666666","text":"Backup of database example finished in 16 minutes\."}/ ' , $ content );
94
94
}
95
95
96
96
private function createHandler ($ authToken = 'token ' , $ authId = 'auth_id ' , $ fromNumber = '+15555555555 ' , $ toNumber = '+16666666666 ' , $ level = Logger::CRITICAL , $ bubble = true , $ useSSL = true , $ host = 'api.plivo.com ' , $ version = PlivoHandler::API_V1 )
97
97
{
98
98
$ constructorArgs = array ($ authToken , $ authId , $ fromNumber , $ toNumber , Logger::DEBUG , true , true , $ host , $ version );
99
99
$ this ->res = fopen ('php://memory ' , 'a ' );
100
- $ this ->handler = $ this ->getMock (
101
- '\Tylercd100\Monolog\Handler\PlivoHandler ' ,
102
- array ('fsockopen ' , 'streamSetTimeout ' , 'closeSocket ' ),
103
- $ constructorArgs
104
- );
100
+ $ this ->handler = $ this ->getMockBuilder (PlivoHandler::class)
101
+ ->setMethods (['fsockopen ' , 'streamSetTimeout ' , 'closeSocket ' ])
102
+ ->setConstructorArgs ($ constructorArgs )
103
+ ->getMock ();
105
104
106
105
$ reflectionProperty = new \ReflectionProperty ('\Monolog\Handler\SocketHandler ' , 'connectionString ' );
107
106
$ reflectionProperty ->setAccessible (true );
0 commit comments