@@ -52,6 +52,27 @@ public function testPfopExecuteAndStatusWithMultipleFops()
5252 $ this ->assertNull ($ error );
5353 }
5454
55+ private function pfopTypeTestData ()
56+ {
57+ return array (
58+ array (
59+ 'type ' => null
60+ ),
61+ array (
62+ 'type ' => -1
63+ ),
64+ array (
65+ 'type ' => 0
66+ ),
67+ array (
68+ 'type ' => 1
69+ ),
70+ array (
71+ 'type ' => 2
72+ )
73+ );
74+ }
75+
5576 public function testPfopWithIdleTimeType ()
5677 {
5778 global $ testAuth ;
@@ -62,23 +83,35 @@ public function testPfopWithIdleTimeType()
6283 $ fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/ ' . $ persistentEntry ;
6384 $ pfop = new PersistentFop ($ testAuth , self ::getConfig ());
6485
65- list ($ id , $ error ) = $ pfop ->execute (
66- $ bucket ,
67- $ key ,
68- $ fops ,
69- null ,
70- null ,
71- false ,
72- 1
73- );
74- $ this ->assertNull ($ error );
75- list ($ status , $ error ) = $ pfop ->status ($ id );
76- $ this ->assertNotNull ($ status );
77- $ this ->assertNull ($ error );
78- $ this ->assertEquals (1 , $ status ['type ' ]);
79- $ this ->assertNotEmpty ($ status ['creationDate ' ]);
86+ $ testCases = $ this ->pfopTypeTestData ();
87+
88+ foreach ($ testCases as $ testCase ) {
89+ list ($ id , $ error ) = $ pfop ->execute (
90+ $ bucket ,
91+ $ key ,
92+ $ fops ,
93+ null ,
94+ null ,
95+ false ,
96+ $ testCase ['type ' ]
97+ );
98+
99+ if (in_array ($ testCase ['type ' ], array (null , 0 , 1 ))) {
100+ $ this ->assertNull ($ error );
101+ list ($ status , $ error ) = $ pfop ->status ($ id );
102+ $ this ->assertNotNull ($ status );
103+ $ this ->assertNull ($ error );
104+ if ($ testCase ['type ' ] == 1 ) {
105+ $ this ->assertEquals (1 , $ status ['type ' ]);
106+ }
107+ $ this ->assertNotEmpty ($ status ['creationDate ' ]);
108+ } else {
109+ $ this ->assertNotNull ($ error );
110+ }
111+ }
80112 }
81113
114+
82115 public function testPfopByUploadPolicy ()
83116 {
84117 global $ testAuth ;
@@ -87,34 +120,53 @@ public function testPfopByUploadPolicy()
87120 $ persistentEntry = \Qiniu \entry ($ bucket , 'test-pfop-type_1 ' );
88121 $ fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/ ' . $ persistentEntry ;
89122
90- $ token = $ testAuth ->uploadToken (
91- $ bucket ,
92- $ key ,
93- 3600 ,
94- array (
95- 'persistentOps ' => $ fops ,
96- 'persistentType ' => 1
97- )
98- );
99- $ upManager = new UploadManager (self ::getConfig ());
100- list ($ ret , $ error ) = $ upManager ->putFile (
101- $ token ,
102- $ key ,
103- __file__,
104- null ,
105- 'text/plain ' ,
106- true
107- );
108- $ this ->assertNull ($ error );
109- $ this ->assertNotEmpty ($ ret ['persistentId ' ]);
110- $ id = $ ret ['persistentId ' ];
123+ $ testCases = $ this ->pfopTypeTestData ();
111124
112- $ pfop = new PersistentFop ($ testAuth , self ::getConfig ());
113- list ($ status , $ error ) = $ pfop ->status ($ id );
114- $ this ->assertNotNull ($ status );
115- $ this ->assertNull ($ error );
116- $ this ->assertEquals (1 , $ status ['type ' ]);
117- $ this ->assertNotEmpty ($ status ['creationDate ' ]);
125+ foreach ($ testCases as $ testCase ) {
126+ $ putPolicy = array (
127+ 'persistentOps ' => $ fops ,
128+ 'persistentType ' => $ testCase ['type ' ]
129+ );
130+
131+ if ($ testCase ['type ' ] == null ) {
132+ unset($ putPolicy ['persistentType ' ]);
133+ }
134+
135+ $ token = $ testAuth ->uploadToken (
136+ $ bucket ,
137+ $ key ,
138+ 3600 ,
139+ $ putPolicy
140+ );
141+ $ upManager = new UploadManager (self ::getConfig ());
142+ list ($ ret , $ error ) = $ upManager ->putFile (
143+ $ token ,
144+ $ key ,
145+ __file__,
146+ null ,
147+ 'text/plain ' ,
148+ true
149+ );
150+
151+ if (in_array ($ testCase ['type ' ], array (null , 0 , 1 ))) {
152+ $ this ->assertNull ($ error );
153+ $ this ->assertNotEmpty ($ ret ['persistentId ' ]);
154+ $ id = $ ret ['persistentId ' ];
155+ } else {
156+ $ this ->assertNotNull ($ error );
157+ return ;
158+ }
159+
160+ $ pfop = new PersistentFop ($ testAuth , self ::getConfig ());
161+ list ($ status , $ error ) = $ pfop ->status ($ id );
162+
163+ $ this ->assertNotNull ($ status );
164+ $ this ->assertNull ($ error );
165+ if ($ testCase ['type ' ] == 1 ) {
166+ $ this ->assertEquals (1 , $ status ['type ' ]);
167+ }
168+ $ this ->assertNotEmpty ($ status ['creationDate ' ]);
169+ }
118170 }
119171
120172 public function testMkzip ()
0 commit comments