44namespace Soap \Encoding \Test \Unit \Encoder \SimpleType ;
55
66use PHPUnit \Framework \Attributes \CoversClass ;
7+ use PHPUnit \Framework \Attributes \DataProvider ;
78use Soap \Encoding \Encoder \SimpleType \Base64BinaryTypeEncoder ;
89use Soap \Encoding \Test \Unit \Encoder \AbstractEncoderTests ;
910use Soap \Engine \Metadata \Model \XsdType ;
@@ -24,4 +25,43 @@ public static function provideIsomorphicCases(): iterable
2425 'data ' => 'hello ' ,
2526 ];
2627 }
28+
29+ /**
30+ * @return iterable<string, array{xml: string, data: string}>
31+ */
32+ public static function provideBase64WithWhitespaceCases (): iterable
33+ {
34+ $ data = 'hello world, this is a longer string for base64 wrapping ' ;
35+ $ encoded = base64_encode ($ data );
36+
37+ yield 'with-line-breaks ' => [
38+ 'xml ' => chunk_split ($ encoded , 76 , "\r\n" ),
39+ 'data ' => $ data ,
40+ ];
41+
42+ yield 'with-spaces ' => [
43+ 'xml ' => chunk_split ($ encoded , 20 , " " ),
44+ 'data ' => $ data ,
45+ ];
46+
47+ yield 'with-mixed-whitespace ' => [
48+ 'xml ' => chunk_split ($ encoded , 30 , "\n\t" ),
49+ 'data ' => $ data ,
50+ ];
51+
52+ yield 'without-padding ' => [
53+ 'xml ' => rtrim (base64_encode ('hello world ' ), '= ' ),
54+ 'data ' => 'hello world ' ,
55+ ];
56+ }
57+
58+ #[DataProvider('provideBase64WithWhitespaceCases ' )]
59+ public function test_it_can_decode_base64_with_whitespace (string $ xml , string $ data ): void
60+ {
61+ $ encoder = new Base64BinaryTypeEncoder ();
62+ $ context = self ::createContext (XsdType::guess ('base64Binary ' ));
63+ $ iso = $ encoder ->iso ($ context );
64+
65+ static ::assertEquals ($ data , $ iso ->from ($ xml ));
66+ }
2767}
0 commit comments