Skip to content

Commit 533627a

Browse files
committed
update test code.
1 parent 5005f7b commit 533627a

File tree

3 files changed

+159
-9
lines changed

3 files changed

+159
-9
lines changed

tests/OSS/Tests/GetBucketTransferAccelerationResultTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testParseValidXml()
3333
$this->assertNotNull($result->getData());
3434
$this->assertNotNull($result->getRawResponse());
3535
$enabled = $result->getData();
36-
$this->assertEquals("true", $enabled);
36+
$this->assertEquals(true, $enabled);
3737
}
3838

3939
public function testParseValidXml1()
@@ -44,18 +44,18 @@ public function testParseValidXml1()
4444
$this->assertNotNull($result->getData());
4545
$this->assertNotNull($result->getRawResponse());
4646
$enabled = $result->getData();
47-
$this->assertEquals("false", $enabled);
47+
$this->assertEquals(false, $enabled);
4848
}
4949

5050
public function testParseInvalidXml2()
5151
{
5252
$response = new ResponseCore(array(), $this->invalidXml2, 200);
5353
$result = new GetBucketTransferAccelerationResult($response);
5454
$this->assertTrue($result->isOK());
55-
$this->assertNull($result->getData());
55+
$this->assertNotNull($result->getData());
5656
$this->assertNotNull($result->getRawResponse());
5757
$this->assertNotNull($result->getRawResponse()->body);
5858
$enabled = $result->getData();
59-
$this->assertNull($enabled);
59+
$this->assertEquals(false, $enabled);
6060
}
6161
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<?php
2+
3+
namespace OSS\Tests;
4+
5+
6+
use OSS\Result\ListObjectsV2Result;
7+
use OSS\Http\ResponseCore;
8+
9+
class ListObjectsV2ResultTest extends \PHPUnit\Framework\TestCase
10+
{
11+
12+
private $validXml1 = <<<BBBB
13+
<?xml version="1.0" encoding="UTF-8"?>
14+
<ListBucketResult>
15+
<Name>testbucket-hf</Name>
16+
<Prefix></Prefix>
17+
<StartAfter></StartAfter>
18+
<MaxKeys>1000</MaxKeys>
19+
<Delimiter>/</Delimiter>
20+
<IsTruncated>false</IsTruncated>
21+
<CommonPrefixes>
22+
<Prefix>oss-php-sdk-test/</Prefix>
23+
</CommonPrefixes>
24+
<CommonPrefixes>
25+
<Prefix>test/</Prefix>
26+
</CommonPrefixes>
27+
</ListBucketResult>
28+
BBBB;
29+
30+
private $validXml2 = <<<BBBB
31+
<?xml version="1.0" encoding="UTF-8"?>
32+
<ListBucketResult>
33+
<Name>testbucket-hf</Name>
34+
<Prefix>oss-php-sdk-test/</Prefix>
35+
<StartAfter>xx</StartAfter>
36+
<MaxKeys>1000</MaxKeys>
37+
<Delimiter>/</Delimiter>
38+
<IsTruncated>false</IsTruncated>
39+
<Contents>
40+
<Key>oss-php-sdk-test/upload-test-object-name.txt</Key>
41+
<LastModified>2015-11-18T03:36:00.000Z</LastModified>
42+
<ETag>"89B9E567E7EB8815F2F7D41851F9A2CD"</ETag>
43+
<Type>Normal</Type>
44+
<Size>13115</Size>
45+
<StorageClass>Standard</StorageClass>
46+
</Contents>
47+
<KeyCount>1</KeyCount>
48+
</ListBucketResult>
49+
BBBB;
50+
51+
private $validXmlWithEncodedKey = <<<BBBB
52+
<?xml version="1.0" encoding="UTF-8"?>
53+
<ListBucketResult>
54+
<Name>testbucket-hf</Name>
55+
<EncodingType>url</EncodingType>
56+
<Prefix>php%2Fprefix</Prefix>
57+
<StartAfter>php%2Fmarker</StartAfter>
58+
<ContinuationToken>1gJiYw--</ContinuationToken>
59+
<NextContinuationToken>CgJiYw--</NextContinuationToken>
60+
<MaxKeys>1000</MaxKeys>
61+
<Delimiter>%2F</Delimiter>
62+
<IsTruncated>true</IsTruncated>
63+
<Contents>
64+
<Key>php/a%2Bb</Key>
65+
<LastModified>2015-11-18T03:36:00.000Z</LastModified>
66+
<ETag>"89B9E567E7EB8815F2F7D41851F9A2CD"</ETag>
67+
<Type>Normal</Type>
68+
<Size>13115</Size>
69+
<StorageClass>Standard</StorageClass>
70+
<Owner>
71+
<ID>cname_user</ID>
72+
<DisplayName>cname_user</DisplayName>
73+
</Owner>
74+
</Contents>
75+
<KeyCount>1</KeyCount>
76+
</ListBucketResult>
77+
BBBB;
78+
79+
public function testParseValidXml1()
80+
{
81+
$response = new ResponseCore(array(), $this->validXml1, 200);
82+
$result = new ListObjectsV2Result($response);
83+
$this->assertTrue($result->isOK());
84+
$this->assertNotNull($result->getData());
85+
$this->assertNotNull($result->getRawResponse());
86+
$objectListInfo = $result->getData();
87+
$this->assertEquals(2, count($objectListInfo->getPrefixList()));
88+
$this->assertEquals(0, count($objectListInfo->getObjectList()));
89+
$this->assertEquals('testbucket-hf', $objectListInfo->getBucketName());
90+
$this->assertEquals('', $objectListInfo->getPrefix());
91+
$this->assertEquals('', $objectListInfo->getStartAfter());
92+
$this->assertEquals(1000, $objectListInfo->getMaxKeys());
93+
$this->assertEquals('/', $objectListInfo->getDelimiter());
94+
$this->assertEquals('false', $objectListInfo->getIsTruncated());
95+
$this->assertEquals(0, $objectListInfo->getKeyCount());
96+
$prefixes = $objectListInfo->getPrefixList();
97+
$this->assertEquals('oss-php-sdk-test/', $prefixes[0]->getPrefix());
98+
$this->assertEquals('test/', $prefixes[1]->getPrefix());
99+
}
100+
101+
public function testParseValidXml2()
102+
{
103+
$response = new ResponseCore(array(), $this->validXml2, 200);
104+
$result = new ListObjectsV2Result($response);
105+
$this->assertTrue($result->isOK());
106+
$this->assertNotNull($result->getData());
107+
$this->assertNotNull($result->getRawResponse());
108+
$objectListInfo = $result->getData();
109+
$this->assertEquals(0, count($objectListInfo->getPrefixList()));
110+
$this->assertEquals(1, count($objectListInfo->getObjectList()));
111+
$this->assertEquals('testbucket-hf', $objectListInfo->getBucketName());
112+
$this->assertEquals('oss-php-sdk-test/', $objectListInfo->getPrefix());
113+
$this->assertEquals('xx', $objectListInfo->getStartAfter());
114+
$this->assertEquals(1000, $objectListInfo->getMaxKeys());
115+
$this->assertEquals('/', $objectListInfo->getDelimiter());
116+
$this->assertEquals('false', $objectListInfo->getIsTruncated());
117+
$this->assertEquals(1, $objectListInfo->getKeyCount());
118+
$objects = $objectListInfo->getObjectList();
119+
$this->assertEquals('oss-php-sdk-test/upload-test-object-name.txt', $objects[0]->getKey());
120+
$this->assertEquals('2015-11-18T03:36:00.000Z', $objects[0]->getLastModified());
121+
$this->assertEquals('"89B9E567E7EB8815F2F7D41851F9A2CD"', $objects[0]->getETag());
122+
$this->assertEquals('Normal', $objects[0]->getType());
123+
$this->assertEquals(13115, $objects[0]->getSize());
124+
$this->assertEquals('Standard', $objects[0]->getStorageClass());
125+
}
126+
127+
public function testParseValidXmlWithEncodedKey()
128+
{
129+
$response = new ResponseCore(array(), $this->validXmlWithEncodedKey, 200);
130+
$result = new ListObjectsV2Result($response);
131+
$this->assertTrue($result->isOK());
132+
$this->assertNotNull($result->getData());
133+
$this->assertNotNull($result->getRawResponse());
134+
$objectListInfo = $result->getData();
135+
$this->assertEquals(0, count($objectListInfo->getPrefixList()));
136+
$this->assertEquals(1, count($objectListInfo->getObjectList()));
137+
$this->assertEquals('testbucket-hf', $objectListInfo->getBucketName());
138+
$this->assertEquals('php/prefix', $objectListInfo->getPrefix());
139+
$this->assertEquals('php/marker', $objectListInfo->getStartAfter());
140+
$this->assertEquals('CgJiYw--', $objectListInfo->getNextContinuationToken());
141+
$this->assertEquals('1gJiYw--', $objectListInfo->getContinuationToken());
142+
$this->assertEquals(1000, $objectListInfo->getMaxKeys());
143+
$this->assertEquals('/', $objectListInfo->getDelimiter());
144+
$this->assertEquals('true', $objectListInfo->getIsTruncated());
145+
$this->assertEquals(1, $objectListInfo->getKeyCount());
146+
$objects = $objectListInfo->getObjectList();
147+
$this->assertEquals('php/a+b', $objects[0]->getKey());
148+
$this->assertEquals('2015-11-18T03:36:00.000Z', $objects[0]->getLastModified());
149+
$this->assertEquals('"89B9E567E7EB8815F2F7D41851F9A2CD"', $objects[0]->getETag());
150+
$this->assertEquals('Normal', $objects[0]->getType());
151+
$this->assertEquals(13115, $objects[0]->getSize());
152+
$this->assertEquals('Standard', $objects[0]->getStorageClass());
153+
}
154+
}

tests/OSS/Tests/OssClientMultipartUploadTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,7 @@ public function testCompleteMultipartUploadWithException()
390390
$listMultipartUploadInfo = $this->ossClient->completeMultipartUpload($this->bucket, $object, $uploadId, null);
391391
$this->assertTrue(false);
392392
} catch (OssException $e) {
393-
$this->assertTrue(true);
394-
if (strpos($e, "listParts must be array type") == false)
395-
{
396-
$this->assertTrue(false);
397-
}
393+
$this->assertEquals('NoSuchUpload', $e->getErrorCode());
398394
}
399395
}
400396

0 commit comments

Comments
 (0)