File tree Expand file tree Collapse file tree 4 files changed +49
-5
lines changed
Expand file tree Collapse file tree 4 files changed +49
-5
lines changed Original file line number Diff line number Diff line change 2525 "require" : {
2626 "php" : " ^8.1" ,
2727 "phrity/util-errorhandler" : " ^1.1" ,
28+ "phrity/util-interpolator" : " ^1.1" ,
2829 "psr/http-factory" : " ^1.0" ,
29- "psr/http-message" : " ^1.1 | ^2.0"
30+ "psr/http-message" : " ^1.1 || ^2.0"
3031 },
3132 "require-dev" : {
3233 "phpstan/phpstan" : " ^2.0" ,
33- "phpunit/phpunit" : " ^10.0 | ^11.0 | ^12.0" ,
34+ "phpunit/phpunit" : " ^10.0 || ^11.0 | | ^12.0" ,
3435 "phrity/net-uri" : " ^2.0" ,
3536 "robiningelbrecht/phpunit-coverage-tools" : " ^1.9" ,
3637 "squizlabs/php_codesniffer" : " ^3.5"
Original file line number Diff line number Diff line change 22
33namespace Phrity \Net ;
44
5+ use Phrity \Util \Interpolator \InterpolatorTrait ;
56use RuntimeException ;
67use Throwable ;
78
1011 */
1112class StreamException extends RuntimeException
1213{
14+ use InterpolatorTrait;
15+
1316 // Stream errors
1417 public const STREAM_DETACHED = 1000 ;
1518 public const NOT_READABLE = 1010 ;
@@ -73,9 +76,7 @@ class StreamException extends RuntimeException
7376 public function __construct (int $ code , array $ data = [], Throwable |null $ previous = null )
7477 {
7578 $ message = self ::$ messages [$ code ];
76- foreach ($ data as $ key => $ content ) {
77- $ message = str_replace ('{ ' . $ key . '} ' , $ content , $ message );
78- }
79+ $ message = $ this ->interpolate ($ message , $ data );
7980 if ($ previous ) {
8081 $ message .= " ( {$ previous ->getMessage ()}) " ;
8182 }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Tests for Net\SocketServer class.
5+ * @package Phrity > Net > Stream
6+ */
7+
8+ namespace Phrity \Net \Test ;
9+
10+ use Phrity \Net \{
11+ Stream ,
12+ StreamContainerInterface ,
13+ StreamFactory ,
14+ };
15+
16+ class StreamContainer implements StreamContainerInterface
17+ {
18+ public function getStream (): Stream
19+ {
20+ $ factory = new StreamFactory ();
21+ return $ factory ->createStream ('This is a temporary test stream ' );
22+ }
23+ }
Original file line number Diff line number Diff line change 1717 StreamCollection ,
1818 StreamException
1919};
20+ use Phrity \Net \Test \StreamContainer ;
2021use Phrity \Net \Uri ;
2122use TypeError ;
2223
@@ -71,6 +72,24 @@ public function testCollection(): void
7172 $ this ->assertCount (1 , $ collection );
7273 }
7374
75+ public function testContainer (): void
76+ {
77+ $ container = new StreamContainer ();
78+ $ collection = new StreamCollection ();
79+ $ this ->assertEquals ('@container ' , $ collection ->attach ($ container , '@container ' ));
80+
81+ $ this ->assertCount (1 , $ collection );
82+ foreach ($ collection as $ key => $ item ) {
83+ $ this ->assertSame ($ container , $ item );
84+ }
85+ foreach ($ collection ->getReadable () as $ key => $ item ) {
86+ $ this ->assertSame ($ container , $ item );
87+ }
88+ foreach ($ collection ->getWritable () as $ key => $ item ) {
89+ $ this ->assertSame ($ container , $ item );
90+ }
91+ }
92+
7493 public function testInvalidTimeout (): void
7594 {
7695 $ collection = new StreamCollection ();
You can’t perform that action at this time.
0 commit comments