How to use withArgs method of are class

Best Mockery code snippet using are.withArgs

MockAdapterTest.php

Source:MockAdapterTest.php Github

copy

Full Screen

...50 'ACL' => $visibility === Visibility::PUBLIC ? 'public-read' : 'private',51 ]);52 }53 $this->legacyMock->shouldReceive('putObject')54 ->withArgs([$arg])->andReturn(new Model());55 }56 public function testCopy(): void57 {58 $this->mockPutObject('file.txt', 'write');59 $this->obsAdapter->write('file.txt', 'write', new Config());60 $this->legacyMock->shouldReceive('copyObject')61 ->withArgs([62 [63 'Bucket' => 'test',64 'Key' => 'copy.txt',65 'CopySource' => 'test/file.txt',66 'MetadataDirective' => 'COPY',67 'ACL' => 'public-read',68 ],69 ])->andReturn(new Model());70 $this->mockGetVisibility('file.txt', Visibility::PUBLIC);71 $this->obsAdapter->copy('file.txt', 'copy.txt', new Config());72 $this->mockGetObject('copy.txt', 'write');73 self::assertSame('write', $this->obsAdapter->read('copy.txt'));74 }75 public function testCopyFailed(): void76 {77 $this->mockPutObject('file.txt', 'write');78 $this->obsAdapter->write('file.txt', 'write', new Config());79 $this->legacyMock->shouldReceive('copyObject')80 ->withArgs([81 [82 'Bucket' => 'test',83 'Key' => 'copy.txt',84 'CopySource' => 'test/file.txt',85 'MetadataDirective' => 'COPY',86 'ACL' => 'public-read',87 ],88 ])->andThrow(new ObsException());89 $this->mockGetVisibility('file.txt', Visibility::PUBLIC);90 $this->expectException(UnableToCopyFile::class);91 $this->obsAdapter->copy('file.txt', 'copy.txt', new Config());92 $this->mockGetObject('copy.txt', 'write');93 self::assertSame('write', $this->obsAdapter->read('copy.txt'));94 }95 private function mockGetObject(string $path, string $body): void96 {97 $this->legacyMock->shouldReceive('getObject')98 ->withArgs([99 [100 'Bucket' => 'test',101 'Key' => $path,102 ],103 ])->andReturn(new Model([104 'Body' => $this->streamFor($body),105 ]));106 }107 public function testCreateDir(): void108 {109 $this->legacyMock->shouldReceive('putObject')110 ->withArgs([111 [112 'ACL' => 'public-read',113 'Bucket' => 'test',114 'Key' => 'path/',115 'Body' => null,116 ],117 ])->andReturn(new Model());118 $this->legacyMock->shouldReceive('listObjects')119 ->withArgs([120 [121 'Bucket' => 'test',122 'Prefix' => 'path/',123 'Delimiter' => '/',124 'MaxKeys' => 1,125 ],126 ])->andReturn(127 new Model([128 'NextMarker' => '',129 'Contents' => [130 [131 'Key' => 'path/',132 'LastModified' => '2021-05-31T06:52:31.942Z',133 'ETag' => 'd41d8cd98f00b204e9800998ecf8427e',134 'Size' => 0,135 'StorageClass' => 'STANDARD_IA',136 'Owner' => [137 'DisplayName' => 'zingimmick',138 'ID' => '0c85ae1126000f380f21c00e77706640',139 ],140 ],141 ],142 ]),143 new Model([144 'NextMarker' => '',145 'Contents' => [],146 ])147 );148 $this->legacyMock->shouldReceive('listObjects')149 ->withArgs([150 [151 'Bucket' => 'test',152 'Prefix' => 'path/',153 'MaxKeys' => 1000,154 'Delimiter' => '/',155 'Marker' => '',156 ],157 ])->andReturn(new Model([158 'NextMarker' => '',159 'Contents' => [160 [161 'Key' => 'path/',162 'LastModified' => '2021-05-31T06:52:31.942Z',163 'ETag' => 'd41d8cd98f00b204e9800998ecf8427e',164 'Size' => 0,165 'StorageClass' => 'STANDARD_IA',166 'Owner' => [167 'DisplayName' => 'zingimmick',168 'ID' => '0c85ae1126000f380f21c00e77706640',169 ],170 ],171 ],172 ]));173 $this->legacyMock->shouldReceive('listObjects')174 ->withArgs([175 [176 'Bucket' => 'test',177 'Prefix' => 'path/',178 'MaxKeys' => 1000,179 'Marker' => '',180 ],181 ])->andReturn(new Model([182 'NextMarker' => '',183 'Contents' => [184 [185 'Key' => 'path/',186 'LastModified' => '2021-05-31T06:52:31.942Z',187 'ETag' => 'd41d8cd98f00b204e9800998ecf8427e',188 'Size' => 0,189 'StorageClass' => 'STANDARD_IA',190 'Owner' => [191 'DisplayName' => 'zingimmick',192 'ID' => '0c85ae1126000f380f21c00e77706640',193 ],194 ],195 ],196 ]));197 $this->legacyMock->shouldReceive('getObjectMetadata')198 ->withArgs([199 [200 'Bucket' => 'test',201 'Key' => 'path/',202 ],203 ])->andReturn(new Model(204 [205 'ContentLength' => 0,206 'Date' => 'Mon, 31 May 2021 06:52:32 GMT',207 'RequestId' => '00000179C13207EF9217A7F5589D2DC6',208 'Id2' => '32AAAQAAEAABAAAQAAEAABAAAQAAEAABCSvXM+dHYwFYYJv2m9y5LibcMVibe3QN',209 'Reserved' => 'amazon, aws and amazon web services are trademarks or registered trademarks of Amazon Technologies, Inc',210 'Expiration' => '',211 'LastModified' => 'Mon, 31 May 2021 06:52:31 GMT',212 'ContentType' => 'binary/octet-stream',213 'ETag' => 'd41d8cd98f00b204e9800998ecf8427e',214 'VersionId' => '',215 'WebsiteRedirectLocation' => '',216 'StorageClass' => 'STANDARD_IA',217 'AllowOrigin' => '',218 'MaxAgeSeconds' => '',219 'ExposeHeader' => '',220 'AllowMethod' => '',221 'AllowHeader' => '',222 'Restore' => '',223 'SseKms' => '',224 'SseKmsKey' => '',225 'SseC' => '',226 'SseCKeyMd5' => '',227 'Metadata' => [],228 'HttpStatusCode' => 200,229 'Reason' => 'OK',230 ]231 ));232 $this->legacyMock->shouldReceive('deleteObjects')233 ->withArgs([234 [235 'Bucket' => 'test',236 'Objects' => [237 [238 'Key' => 'path/',239 ],240 ],241 ],242 ]);243 $this->obsAdapter->createDirectory('path', new Config());244 self::assertTrue($this->obsAdapter->directoryExists('path'));245 self::assertSame([], iterator_to_array($this->obsAdapter->listContents('path', false)));246 $this->obsAdapter->deleteDirectory('path');247 self::assertFalse($this->obsAdapter->directoryExists('path'));248 }249 public function testSetVisibility(): void250 {251 $this->mockPutObject('file.txt', 'write');252 $this->obsAdapter->write('file.txt', 'write', new Config());253 $this->legacyMock->shouldReceive('getObjectAcl')254 ->withArgs([255 [256 'Bucket' => 'test',257 'Key' => 'file.txt',258 ],259 ])260 ->andReturns(new Model([261 'ContentLength' => '508',262 'Date' => 'Mon, 31 May 2021 06:52:31 GMT',263 'RequestId' => '00000179C132050392179DB73EB80FFF',264 'Id2' => '32AAAQAAEAABAAAQAAEAABAAAQAAEAABCS7X7CQo6PJncbE/Rw7pAST9+g4eSFFj',265 'Reserved' => 'amazon, aws and amazon web services are trademarks or registered trademarks of Amazon Technologies, Inc',266 'Owner' => [267 'DisplayName' => 'zingimmick',268 'ID' => '0c85ae1126000f380f21c00e77706640',269 ],270 'Grants' => [271 [272 'Grantee' => [273 'DisplayName' => 'zingimmick',274 'ID' => '0c85ae1126000f380f21c00e77706640',275 'URI' => '',276 'Permission' => 'FULL_CONTROL',277 ],278 'VersionId' => '',279 'HttpStatusCode' => 200,280 'Reason' => 'OK',281 ],282 ],283 ]), new Model([284 'ContentLength' => '700',285 'Date' => 'Mon, 31 May 2021 06:52:31 GMT',286 'RequestId' => '00000179C132055792179EAE74DFD216',287 'Id2' => '32AAAQAAEAABAAAQAAEAABAAAQAAEAABCSdxGpEHY4PlHymn9n5tgYbtJp4AkMer',288 'Reserved' => 'amazon, aws and amazon web services are trademarks or registered trademarks of Amazon Technologies, Inc',289 'Owner' => [290 'DisplayName' => 'zingimmick',291 'ID' => '0c85ae1126000f380f21c00e77706640',292 ],293 'Grants' => [294 [295 'Grantee' => [296 'DisplayName' => 'zingimmick',297 'ID' => '0c85ae1126000f380f21c00e77706640',298 'URI' => '',299 ],300 'Permission' => 'FULL_CONTROL',301 ],302 [303 'Grantee' => [304 'DisplayName' => '',305 'ID' => '',306 'URI' => 'http://acs.amazonaws.com/groups/global/AllUsers',307 ],308 'Permission' => 'READ',309 ],310 ],311 'VersionId' => '',312 'HttpStatusCode' => 200,313 'Reason' => 'OK',314 ]));315 self::assertSame(Visibility::PRIVATE, $this->obsAdapter->visibility('file.txt')->visibility());316 $this->legacyMock->shouldReceive('setObjectAcl')317 ->withArgs([318 [319 'Bucket' => 'test',320 'Key' => 'file.txt',321 'ACL' => 'public-read',322 ],323 ])->andReturn(new Model([324 'ContentLength' => '0',325 'Date' => 'Mon, 31 May 2021 06:52:31 GMT',326 'RequestId' => '00000179C132053492179E666378BF10',327 'Id2' => '32AAAUgAIAABAAAQAAEAABAAAQAAEAABCSFbUsDzX172DxJwfaphYILIunSuoAAR',328 'Reserved' => 'amazon, aws and amazon web services are trademarks or registered trademarks of Amazon Technologies, Inc',329 'HttpStatusCode' => 200,330 'Reason' => 'OK',331 ]));332 $this->obsAdapter->setVisibility('file.txt', Visibility::PUBLIC);333 self::assertSame(Visibility::PUBLIC, $this->obsAdapter->visibility('file.txt')['visibility']);334 }335 public function testRename(): void336 {337 $this->mockPutObject('from.txt', 'write');338 $this->obsAdapter->write('from.txt', 'write', new Config());339 $this->mockGetMetadata('from.txt');340 self::assertTrue($this->obsAdapter->fileExists('from.txt'));341 $this->legacyMock->shouldReceive('getObjectMetadata')342 ->withArgs([343 [344 'Bucket' => 'test',345 'Key' => 'to.txt',346 ],347 ])->andThrow(new ObsException());348 self::assertFalse($this->obsAdapter->fileExists('to.txt'));349 $this->legacyMock->shouldReceive('copyObject')350 ->withArgs([351 [352 'Bucket' => 'test',353 'Key' => 'to.txt',354 'CopySource' => 'test/from.txt',355 'MetadataDirective' => 'COPY',356 'ACL' => 'public-read',357 ],358 ])->andReturn(new Model());359 $this->legacyMock->shouldReceive('deleteObject')360 ->withArgs([361 [362 'Bucket' => 'test',363 'Key' => 'from.txt',364 ],365 ])->andReturn(new Model());366 $this->mockGetVisibility('from.txt', Visibility::PUBLIC);367 $this->obsAdapter->move('from.txt', 'to.txt', new Config());368 $this->legacyMock->shouldReceive('getObjectMetadata')369 ->withArgs([370 [371 'Bucket' => 'test',372 'Key' => 'from.txt',373 ],374 ])->andThrow(new ObsException());375 self::assertFalse($this->obsAdapter->fileExists('from.txt'));376 $this->mockGetObject('to.txt', 'write');377 self::assertSame('write', $this->obsAdapter->read('to.txt'));378 $this->legacyMock->shouldReceive('deleteObject')379 ->withArgs([380 [381 'Bucket' => 'test',382 'Key' => 'to.txt',383 ],384 ])->andReturn(new Model());385 $this->obsAdapter->delete('to.txt');386 }387 public function testDeleteDir(): void388 {389 $this->legacyMock->shouldReceive('listObjects')390 ->withArgs([391 [392 'Bucket' => 'test',393 'Prefix' => 'path/',394 'MaxKeys' => 1000,395 'Marker' => '',396 ],397 ])->andReturn(new Model([398 'ContentLength' => '864',399 'Date' => 'Mon, 31 May 2021 06:52:32 GMT',400 'RequestId' => '00000179C13207949217A6C3460097BF',401 'Id2' => '32AAAQAAEAABAAAQAAEAABAAAQAAEAABCSeDHUY9dqA1oi7BKX+IbcUaoAQHmnMG',402 'Reserved' => 'amazon, aws and amazon web services are trademarks or registered trademarks of Amazon Technologies, Inc',403 'IsTruncated' => false,404 'Marker' => '',405 'NextMarker' => '',406 'Contents' => [407 [408 'Key' => 'path/',409 'LastModified' => '2021-05-31T06:52:31.942Z',410 'ETag' => '"d41d8cd98f00b204e9800998ecf8427e"',411 'Size' => 0,412 'StorageClass' => 'STANDARD_IA',413 'Owner' => [414 'DisplayName' => 'zingimmick',415 'ID' => '0c85ae1126000f380f21c00e77706640',416 ],417 ], [418 'Key' => 'path/file.txt',419 'LastModified' => '2021-05-31T06:52:32.001Z',420 'ETag' => '"098f6bcd4621d373cade4e832627b4f6"',421 'Size' => 4,422 'StorageClass' => 'STANDARD_IA',423 'Owner' => [424 'DisplayName' => 'zingimmick',425 'ID' => '0c85ae1126000f380f21c00e77706640',426 ],427 ],428 ],429 'Name' => 'test',430 'Prefix' => 'path/',431 'Delimiter' => '/',432 'MaxKeys' => 1000,433 'CommonPrefixes' => [],434 'Location' => 'cn-east-3',435 'HttpStatusCode' => 200,436 'Reason' => 'OK',437 ]));438 $this->mockGetMetadata('path/');439 $this->mockGetMetadata('path/file.txt');440 $this->legacyMock->shouldReceive('getObjectMetadata')441 ->withArgs([442 [443 'Bucket' => 'test',444 'Key' => 'path',445 ],446 ])->andThrow(new ObsException());447 $this->legacyMock->shouldReceive('deleteObjects')448 ->withArgs([449 [450 'Bucket' => 'test',451 'Objects' => [452 [453 'Key' => 'path/',454 ],455 [456 'Key' => 'path/file.txt',457 ],458 ],459 ],460 ])->andReturn(new Model());461 $this->obsAdapter->deleteDirectory('path');462 self::assertTrue(true);463 }464 public function testWriteStream(): void465 {466 $contents = $this->streamForResource('write');467 $this->mockPutObject('file.txt', $contents);468 $this->obsAdapter->writeStream('file.txt', $contents, new Config());469 $this->mockGetObject('file.txt', 'write');470 self::assertSame('write', $this->obsAdapter->read('file.txt'));471 }472 /**473 * @return \Iterator<string[]>474 */475 public function provideVisibilities(): \Iterator476 {477 yield [Visibility::PUBLIC];478 yield [Visibility::PRIVATE];479 }480 private function mockGetVisibility(string $path, string $visibility): void481 {482 $model = new Model([483 'ContentLength' => '508',484 'Date' => 'Mon, 31 May 2021 06:52:31 GMT',485 'RequestId' => '00000179C132050392179DB73EB80FFF',486 'Id2' => '32AAAQAAEAABAAAQAAEAABAAAQAAEAABCS7X7CQo6PJncbE/Rw7pAST9+g4eSFFj',487 'Reserved' => 'amazon, aws and amazon web services are trademarks or registered trademarks of Amazon Technologies, Inc',488 'Owner' => [489 'DisplayName' => 'zingimmick',490 'ID' => '0c85ae1126000f380f21c00e77706640',491 ],492 'Grants' => $visibility === Visibility::PRIVATE ? [493 [494 'Grantee' => [495 'DisplayName' => 'zingimmick',496 'ID' => '0c85ae1126000f380f21c00e77706640',497 'URI' => '',498 ],499 'Permission' => 'FULL_CONTROL',500 ],501 ] : [502 [503 'Grantee' => [504 'DisplayName' => 'zingimmick',505 'ID' => '0c85ae1126000f380f21c00e77706640',506 'URI' => '',507 ],508 'Permission' => 'FULL_CONTROL',509 ],510 [511 'Grantee' => [512 'DisplayName' => '',513 'ID' => '',514 'URI' => 'http://acs.amazonaws.com/groups/global/AllUsers',515 ],516 'Permission' => 'READ',517 ],518 ],519 'VersionId' => '',520 'HttpStatusCode' => 200,521 'Reason' => 'OK',522 ]);523 $this->legacyMock->shouldReceive('getObjectAcl')524 ->withArgs([525 [526 'Bucket' => 'test',527 'Key' => $path,528 ],529 ])530 ->andReturn($model);531 }532 /**533 * @dataProvider provideVisibilities534 */535 public function testWriteStreamWithVisibility(string $visibility): void536 {537 $contents = $this->streamForResource('write');538 $this->mockPutObject('file.txt', $contents, $visibility);539 $this->obsAdapter->writeStream('file.txt', $contents, new Config([540 'visibility' => $visibility,541 ]));542 $this->mockGetVisibility('file.txt', $visibility);543 self::assertSame($visibility, $this->obsAdapter->visibility('file.txt')['visibility']);544 }545 public function testWriteStreamWithExpires(): void546 {547 $contents = $this->streamForResource('write');548 $this->legacyMock->shouldReceive('putObject')549 ->withArgs([550 [551 'ContentType' => 'text/plain',552 'Expires' => 20,553 'Bucket' => 'test',554 'Key' => 'file.txt',555 'Body' => $contents,556 ],557 ])->andReturn(new Model());558 $this->obsAdapter->writeStream('file.txt', $contents, new Config([559 'Expires' => 20,560 ]));561 $this->mockGetObject('file.txt', 'write');562 self::assertSame('write', $this->obsAdapter->read('file.txt'));563 }564 public function testWriteStreamWithMimetype(): void565 {566 $contents = $this->streamForResource('write');567 $this->legacyMock->shouldReceive('putObject')568 ->withArgs([569 [570 'ContentType' => 'image/png',571 'Bucket' => 'test',572 'Key' => 'file.txt',573 'Body' => $contents,574 ],575 ])->andReturn(new Model());576 $this->obsAdapter->writeStream('file.txt', $contents, new Config([577 'ContentType' => 'image/png',578 ]));579 $this->legacyMock->shouldReceive('getObjectMetadata')580 ->once()581 ->withArgs([582 [583 'Bucket' => 'test',584 'Key' => 'file.txt',585 ],586 ])->andReturn(new Model([587 'ContentLength' => 9,588 'Date' => 'Mon, 31 May 2021 06:52:32 GMT',589 'RequestId' => '00000179C13207FD9217A8324EE5B315',590 'Id2' => '32AAAQAAEAABAAAQAAEAABAAAQAAEAABCSOcy2Ri+ilXxrwc5JIVg6ifOFbyOU/p',591 'Reserved' => 'amazon, aws and amazon web services are trademarks or registered trademarks of Amazon Technologies, Inc',592 'Expiration' => '',593 'LastModified' => 'Mon, 31 May 2021 06:52:32 GMT',594 'ContentType' => 'image/png',595 'ETag' => '"098f6bcd4621d373cade4e832627b4f6"',596 'VersionId' => '',597 'WebsiteRedirectLocation' => '',598 'StorageClass' => 'STANDARD_IA',599 'AllowOrigin' => '',600 'MaxAgeSeconds' => '',601 'ExposeHeader' => '',602 'AllowMethod' => '',603 'AllowHeader' => '',604 'Restore' => '',605 'SseKms' => '',606 'SseKmsKey' => '',607 'SseC' => '',608 'SseCKeyMd5' => '',609 'Metadata' => [],610 'HttpStatusCode' => 200,611 'Reason' => 'OK',612 ]));613 self::assertSame('image/png', $this->obsAdapter->mimeType('file.txt')['mime_type']);614 }615 public function testDelete(): void616 {617 $contents = $this->streamForResource('write');618 $this->mockPutObject('file.txt', $contents);619 $this->obsAdapter->writeStream('file.txt', $contents, new Config());620 $this->mockGetMetadata('file.txt');621 self::assertTrue($this->obsAdapter->fileExists('file.txt'));622 $this->legacyMock->shouldReceive('deleteObject')623 ->withArgs([624 [625 'Bucket' => 'test',626 'Key' => 'file.txt',627 ],628 ])->andReturn(new Model());629 $this->obsAdapter->delete('file.txt');630 $this->legacyMock->shouldReceive('getObjectMetadata')631 ->withArgs([632 [633 'Bucket' => 'test',634 'Key' => 'file.txt',635 ],636 ])->andThrow(new ObsException());637 self::assertFalse($this->obsAdapter->fileExists('file.txt'));638 }639 public function testWrite(): void640 {641 $this->mockPutObject('file.txt', 'write');642 $this->obsAdapter->write('file.txt', 'write', new Config());643 $this->mockGetObject('file.txt', 'write');644 self::assertSame('write', $this->obsAdapter->read('file.txt'));645 }646 public function testRead(): void647 {648 $this->mockGetObject('fixture/read.txt', 'read-test');649 self::assertSame('read-test', $this->obsAdapter->read('fixture/read.txt'));650 }651 public function testReadStream(): void652 {653 $this->mockGetObject('fixture/read.txt', 'read-test');654 self::assertSame('read-test', stream_get_contents($this->obsAdapter->readStream('fixture/read.txt')));655 }656 public function testGetVisibility(): void657 {658 $this->legacyMock->shouldReceive('getObjectAcl')659 ->withArgs([660 [661 'Bucket' => 'test',662 'Key' => 'fixture/read.txt',663 ],664 ])665 ->andReturn(new Model([666 'ContentLength' => '508',667 'Date' => 'Mon, 31 May 2021 06:52:31 GMT',668 'RequestId' => '00000179C132050392179DB73EB80FFF',669 'Id2' => '32AAAQAAEAABAAAQAAEAABAAAQAAEAABCS7X7CQo6PJncbE/Rw7pAST9+g4eSFFj',670 'Reserved' => 'amazon, aws and amazon web services are trademarks or registered trademarks of Amazon Technologies, Inc',671 'Owner' => [672 'DisplayName' => 'zingimmick',673 'ID' => '0c85ae1126000f380f21c00e77706640',674 ],675 'Grants' => [676 [677 'Grantee' => [678 'DisplayName' => 'zingimmick',679 'ID' => '0c85ae1126000f380f21c00e77706640',680 'URI' => '',681 'Permission' => 'FULL_CONTROL',682 ],683 'VersionId' => '',684 'HttpStatusCode' => 200,685 'Reason' => 'OK',686 ],687 ],688 ]));689 self::assertSame(Visibility::PRIVATE, $this->obsAdapter->visibility('fixture/read.txt')['visibility']);690 }691 private function mockGetMetadata(string $path): void692 {693 $this->legacyMock->shouldReceive('getObjectMetadata')694 ->once()695 ->withArgs([696 [697 'Bucket' => 'test',698 'Key' => $path,699 ],700 ])->andReturn(new Model([701 'ContentLength' => 9,702 'Date' => 'Mon, 31 May 2021 06:52:32 GMT',703 'RequestId' => '00000179C13207FD9217A8324EE5B315',704 'Id2' => '32AAAQAAEAABAAAQAAEAABAAAQAAEAABCSOcy2Ri+ilXxrwc5JIVg6ifOFbyOU/p',705 'Reserved' => 'amazon, aws and amazon web services are trademarks or registered trademarks of Amazon Technologies, Inc',706 'Expiration' => '',707 'LastModified' => 'Mon, 31 May 2021 06:52:32 GMT',708 'ContentType' => 'text/plain',709 'ETag' => '"098f6bcd4621d373cade4e832627b4f6"',710 'VersionId' => '',711 'WebsiteRedirectLocation' => '',712 'StorageClass' => 'STANDARD_IA',713 'AllowOrigin' => '',714 'MaxAgeSeconds' => '',715 'ExposeHeader' => '',716 'AllowMethod' => '',717 'AllowHeader' => '',718 'Restore' => '',719 'SseKms' => '',720 'SseKmsKey' => '',721 'SseC' => '',722 'SseCKeyMd5' => '',723 'Metadata' => [],724 'HttpStatusCode' => 200,725 'Reason' => 'OK',726 ]));727 }728 private function mockGetEmptyMetadata(string $path): void729 {730 $this->legacyMock->shouldReceive('getObjectMetadata')731 ->once()732 ->withArgs([733 [734 'Bucket' => 'test',735 'Key' => $path,736 ],737 ])->andReturn(new Model([738 'ContentLength' => null,739 'Date' => 'Mon, 31 May 2021 06:52:32 GMT',740 'RequestId' => '00000179C13207FD9217A8324EE5B315',741 'Id2' => '32AAAQAAEAABAAAQAAEAABAAAQAAEAABCSOcy2Ri+ilXxrwc5JIVg6ifOFbyOU/p',742 'Reserved' => 'amazon, aws and amazon web services are trademarks or registered trademarks of Amazon Technologies, Inc',743 'Expiration' => '',744 'LastModified' => null,745 'ContentType' => null,746 'ETag' => '"098f6bcd4621d373cade4e832627b4f6"',747 'VersionId' => '',748 'WebsiteRedirectLocation' => '',749 'StorageClass' => 'STANDARD_IA',750 'AllowOrigin' => '',751 'MaxAgeSeconds' => '',752 'ExposeHeader' => '',753 'AllowMethod' => '',754 'AllowHeader' => '',755 'Restore' => '',756 'SseKms' => '',757 'SseKmsKey' => '',758 'SseC' => '',759 'SseCKeyMd5' => '',760 'Metadata' => [],761 'HttpStatusCode' => 200,762 'Reason' => 'OK',763 ]));764 }765 public function testListContents(): void766 {767 $this->legacyMock->shouldReceive('listObjects')768 ->withArgs([769 [770 'Bucket' => 'test',771 'Delimiter' => '/',772 'Prefix' => 'path/',773 'MaxKeys' => 1000,774 'Marker' => '',775 ],776 ])->andReturn(777 new Model([778 'ContentLength' => '566',779 'Date' => 'Mon, 31 May 2021 15:23:25 GMT',780 'RequestId' => '00000179C305C54B920E25B74672EEBF',781 'Id2' => '32AAAQAAEAABAAAQAAEAABAAAQAAEAABCSfHbGTCJ9SuSxR2hiyYh0eEyU5XfrC0',782 'Reserved' => 'amazon, aws and amazon web services are trademarks or registered trademarks of Amazon Technologies, Inc',783 'IsTruncated' => false,784 'Marker' => '',785 'NextMarker' => '',786 'Contents' => [787 [788 'Key' => 'path/',789 'LastModified' => '2021-05-31T15:23:24.217Z',790 'ETag' => '"d41d8cd98f00b204e9800998ecf8427e"',791 'Size' => 0,792 'StorageClass' => 'STANDARD_IA',793 'Owner' => [794 'DisplayName' => 'zingimmick',795 'ID' => '0c85ae1126000f380f21c00e77706640',796 ],797 ],798 ],799 'Name' => 'test',800 'Prefix' => 'path/',801 'Delimiter' => '/',802 'MaxKeys' => 1000,803 'CommonPrefixes' => [],804 'Location' => 'cn-east-3',805 'HttpStatusCode' => 200,806 'Reason' => 'OK',807 ])808 );809 $this->legacyMock->shouldReceive('getObjectMetadata')810 ->withArgs([811 [812 'Bucket' => 'test',813 'Key' => 'path/',814 ],815 ])->andReturn(new Model(816 [817 'ContentLength' => 0,818 'Date' => 'Mon, 31 May 2021 06:52:32 GMT',819 'RequestId' => '00000179C13207EF9217A7F5589D2DC6',820 'Id2' => '32AAAQAAEAABAAAQAAEAABAAAQAAEAABCSvXM+dHYwFYYJv2m9y5LibcMVibe3QN',821 'Reserved' => 'amazon, aws and amazon web services are trademarks or registered trademarks of Amazon Technologies, Inc',822 'Expiration' => '',823 'LastModified' => 'Mon, 31 May 2021 06:52:31 GMT',824 'ContentType' => 'binary/octet-stream',825 'ETag' => 'd41d8cd98f00b204e9800998ecf8427e',826 'VersionId' => '',827 'WebsiteRedirectLocation' => '',828 'StorageClass' => 'STANDARD_IA',829 'AllowOrigin' => '',830 'MaxAgeSeconds' => '',831 'ExposeHeader' => '',832 'AllowMethod' => '',833 'AllowHeader' => '',834 'Restore' => '',835 'SseKms' => '',836 'SseKmsKey' => '',837 'SseC' => '',838 'SseCKeyMd5' => '',839 'Metadata' => [],840 'HttpStatusCode' => 200,841 'Reason' => 'OK',842 ]843 ));844 self::assertNotEmpty($this->obsAdapter->listContents('path', false));845 $this->legacyMock->shouldReceive('listObjects')846 ->withArgs([847 [848 'Bucket' => 'test',849 'Delimiter' => '/',850 'Prefix' => 'path1/',851 'MaxKeys' => 1000,852 'Marker' => '',853 ],854 ])->andReturn(new Model([855 'NextMarker' => '',856 'Contents' => [],857 ]));858 self::assertEmpty(iterator_to_array($this->obsAdapter->listContents('path1', false)));859 $this->mockPutObject('a/b/file.txt', 'test');860 $this->obsAdapter->write('a/b/file.txt', 'test', new Config());861 $this->legacyMock->shouldReceive('listObjects')862 ->withArgs([863 [864 'Bucket' => 'test',865 'Prefix' => 'a/',866 'MaxKeys' => 1000,867 'Marker' => '',868 ],869 ])->andReturn(new Model([870 'ContentLength' => '333',871 'Date' => 'Mon, 31 May 2021 15:23:25 GMT',872 'RequestId' => '00000179C305C593920E2644AED41021',873 'Id2' => '32AAAQAAEAABAAAQAAEAABAAAQAAEAABCSYw8g3pRtVZNn+ok4GA5fOUfUpb7nSm',874 'Reserved' => 'amazon, aws and amazon web services are trademarks or registered trademarks of Amazon Technologies, Inc',875 'IsTruncated' => false,876 'Marker' => '',877 'NextMarker' => '',878 'Contents' => [879 [880 'Key' => 'a/b/file.txt',881 'LastModified' => '2021-05-31T15:23:24.217Z',882 'ETag' => 'd41d8cd98f00b204e9800998ecf8427e',883 'Size' => 9,884 'StorageClass' => 'STANDARD_IA',885 'Owner' => [886 'DisplayName' => 'zingimmick',887 'ID' => '0c85ae1126000f380f21c00e77706640',888 ],889 ],890 ],891 'Name' => 'test',892 'Prefix' => 'a/',893 'Delimiter' => '/',894 'MaxKeys' => 1000,895 'CommonPrefixes' => [896 [897 'Prefix' => 'a/b/',898 ],899 ],900 'Location' => 'cn-east-3',901 'HttpStatusCode' => 200,902 'Reason' => 'OK',903 ]));904 $this->legacyMock->shouldReceive('listObjects')905 ->withArgs([906 [907 'Bucket' => 'test',908 'Prefix' => 'a/b/',909 'MaxKeys' => 1000,910 'Marker' => '',911 ],912 ])->andReturn(new Model([913 'ContentLength' => '333',914 'Date' => 'Mon, 31 May 2021 15:23:25 GMT',915 'RequestId' => '00000179C305C593920E2644AED41021',916 'Id2' => '32AAAQAAEAABAAAQAAEAABAAAQAAEAABCSYw8g3pRtVZNn+ok4GA5fOUfUpb7nSm',917 'Reserved' => 'amazon, aws and amazon web services are trademarks or registered trademarks of Amazon Technologies, Inc',918 'IsTruncated' => false,919 'Marker' => '',920 'NextMarker' => '',921 'Contents' => [922 [923 'Key' => 'a/b/file.txt',924 'LastModified' => '2021-05-31T15:23:24.217Z',925 'ETag' => 'd41d8cd98f00b204e9800998ecf8427e',926 'Size' => 9,927 'StorageClass' => 'STANDARD_IA',928 'Owner' => [929 'DisplayName' => 'zingimmick',930 'ID' => '0c85ae1126000f380f21c00e77706640',931 ],932 ],933 ],934 'Name' => 'test',935 'Prefix' => 'a/b/',936 'Delimiter' => '/',937 'MaxKeys' => 1000,938 'CommonPrefixes' => [],939 'Location' => 'cn-east-3',940 'HttpStatusCode' => 200,941 'Reason' => 'OK',942 ]));943 $this->mockGetMetadata('a/b/file.txt');944 $contents = iterator_to_array($this->obsAdapter->listContents('a', true));945 self::assertContainsOnlyInstancesOf(StorageAttributes::class, $contents);946 self::assertCount(2, $contents);947 /** @var \League\Flysystem\FileAttributes $file */948 $file = $contents[0];949 self::assertInstanceOf(FileAttributes::class, $file);950 self::assertSame('a/b/file.txt', $file->path());951 self::assertSame(9, $file->fileSize());952 self::assertNull($file->mimeType());953 self::assertSame(1622474604, $file->lastModified());954 self::assertNull($file->visibility());955 self::assertSame([956 'StorageClass' => 'STANDARD_IA',957 'ETag' => 'd41d8cd98f00b204e9800998ecf8427e',958 ], $file->extraMetadata());959 /** @var \League\Flysystem\DirectoryAttributes $directory */960 $directory = $contents[1];961 self::assertInstanceOf(DirectoryAttributes::class, $directory);962 self::assertSame('a/b', $directory->path());963 }964 public function testGetSize(): void965 {966 $this->mockGetMetadata('fixture/read.txt');967 self::assertSame(9, $this->obsAdapter->fileSize('fixture/read.txt')->fileSize());968 }969 public function testGetSizeError(): void970 {971 $this->mockGetEmptyMetadata('fixture/read.txt');972 $this->expectException(UnableToRetrieveMetadata::class);973 self::assertSame(9, $this->obsAdapter->fileSize('fixture/read.txt')->fileSize());974 }975 public function testGetTimestamp(): void976 {977 $this->mockGetMetadata('fixture/read.txt');978 self::assertSame(1622443952, $this->obsAdapter->lastModified('fixture/read.txt')->lastModified());979 }980 public function testGetTimestampError(): void981 {982 $this->mockGetEmptyMetadata('fixture/read.txt');983 $this->expectException(UnableToRetrieveMetadata::class);984 self::assertSame(1622443952, $this->obsAdapter->lastModified('fixture/read.txt')->lastModified());985 }986 public function testGetMimetype(): void987 {988 $this->mockGetMetadata('fixture/read.txt');989 self::assertSame('text/plain', $this->obsAdapter->mimeType('fixture/read.txt')->mimeType());990 }991 public function testGetMimetypeError(): void992 {993 $this->mockGetEmptyMetadata('fixture/read.txt');994 $this->expectException(UnableToRetrieveMetadata::class);995 self::assertSame('text/plain', $this->obsAdapter->mimeType('fixture/read.txt')->mimeType());996 }997 public function testGetMetadataError(): void998 {999 $this->mockGetEmptyMetadata('fixture/');1000 $this->expectException(UnableToRetrieveMetadata::class);1001 self::assertSame('text/plain', $this->obsAdapter->mimeType('fixture/')->mimeType());1002 }1003 public function testHas(): void1004 {1005 $this->mockGetMetadata('fixture/read.txt');1006 self::assertTrue($this->obsAdapter->fileExists('fixture/read.txt'));1007 }1008 public function testGetTemporaryUrl(): void1009 {1010 $this->legacyMock->shouldReceive('createSignedUrl')1011 ->withArgs([1012 [1013 'Method' => 'GET',1014 'Bucket' => 'test',1015 'Key' => 'fixture/read.txt',1016 'Expires' => 10,1017 'QueryParams' => [],1018 ],1019 ])->andReturn(new Model([1020 'SignedUrl' => 'signed-url',1021 ]));1022 self::assertSame('signed-url', $this->obsAdapter->getTemporaryUrl('fixture/read.txt', 10, []));1023 }1024 public function testDirectoryExists(): void1025 {1026 $this->legacyMock->shouldReceive('listObjects')1027 ->withArgs([1028 [1029 'Bucket' => 'test',1030 'Prefix' => 'fixture/exists-directory/',1031 'Delimiter' => '/',1032 'MaxKeys' => 1,1033 ],1034 ])->andReturn(new Model([1035 'ContentLength' => '302',1036 'Date' => 'Sun, 16 Jan 2022 09:26:08 GMT',1037 'RequestId' => '0000017E6235507D950E8EB369D41D99',1038 'Id2' => '32AAAQAAEAABAAAQAAEAABAAAQAAEAABCSZadwpdiOENxOcC8idIIBfPBMDPTNFd',1039 'Reserved' => '',1040 'IsTruncated' => false,1041 'Marker' => '',1042 'NextMarker' => '',1043 'Contents' => [],1044 'Name' => 'zing-test',1045 'Prefix' => 'fixture/exists-directory/',1046 'Delimiter' => '/',1047 'MaxKeys' => 1000,1048 'CommonPrefixes' => [],1049 'Location' => 'cn-east-3',1050 'HttpStatusCode' => 200,1051 'Reason' => 'OK',1052 ]), new Model([1053 'ContentLength' => '302',1054 'Date' => 'Sun, 16 Jan 2022 09:26:08 GMT',1055 'RequestId' => '0000017E6235507D950E8EB369D41D99',1056 'Id2' => '32AAAQAAEAABAAAQAAEAABAAAQAAEAABCSZadwpdiOENxOcC8idIIBfPBMDPTNFd',1057 'Reserved' => '',1058 'IsTruncated' => false,1059 'Marker' => '',1060 'NextMarker' => '',1061 'Contents' => [1062 [1063 'Key' => 'fixture/exists-directory/',1064 'LastModified' => '2022-01-16T09:29:18.390Z',1065 'ETag' => 'd41d8cd98f00b204e9800998ecf8427e',1066 'Size' => 0,1067 'StorageClass' => 'WARM',1068 'Type' => '',1069 'Owner' => [1070 [1071 'ID' => '0c85ae1126000f380f21c00e77706640',1072 ],1073 ],1074 ],1075 ],1076 'Name' => 'zing-test',1077 'Prefix' => 'fixture/exists-directory/',1078 'Delimiter' => '/',1079 'MaxKeys' => 1000,1080 'CommonPrefixes' => [],1081 'Location' => 'cn-east-3',1082 'HttpStatusCode' => 200,1083 'Reason' => 'OK',1084 ]));1085 $this->legacyMock->shouldReceive('putObject')1086 ->withArgs([1087 [1088 'ACL' => 'public-read',1089 'Bucket' => 'test',1090 'Key' => 'fixture/exists-directory/',1091 'Body' => null,1092 ],1093 ])->andReturn(new Model());1094 self::assertFalse($this->obsAdapter->directoryExists('fixture/exists-directory'));1095 $this->obsAdapter->createDirectory('fixture/exists-directory', new Config());1096 self::assertTrue($this->obsAdapter->directoryExists('fixture/exists-directory'));1097 }1098}...

Full Screen

Full Screen

CleanUnusedTest.php

Source:CleanUnusedTest.php Github

copy

Full Screen

...87 $this->project_1->shouldReceive("getUnixName")->andReturn('project_1');88 $this->project_2->shouldReceive("getUnixName")->andReturn('project_2');89 $this->project_3->shouldReceive("getUnixName")->andReturn('project_3');90 $this->project_manager = Mockery::mock(ProjectManager::class);91 $this->project_manager->shouldReceive('getProject')->withArgs([101])->andReturn($this->project_1);92 $this->project_manager->shouldReceive('getProject')->withArgs([102])->andReturn($this->project_2);93 $this->project_manager->shouldReceive('getProject')->withArgs([103])->andReturn($this->project_3);94 $this->dao = Mockery::mock(CleanUnusedDao::class);95 $this->initDao();96 $this->backend = Mockery::mock(Backend::class);97 $this->media_wiki_dao = Mockery::mock(MediawikiDao::class);98 $this->data_dir = Mockery::mock(MediawikiDataDir::class);99 $this->clean_unused = new CleanUnused(100 $this->logger,101 $this->dao,102 $this->project_manager,103 $this->backend,104 $this->media_wiki_dao,105 $this->data_dir106 );107 }108 private function initLogger(): void109 {110 $this->logger->shouldReceive('log')->withArgs([LogLevel::INFO, "[MW Purge] Start purge", []])->once();111 $this->logger->shouldReceive('log')->withArgs([LogLevel::INFO, "[MW Purge] End of purge of used but empty mediawiki on projects which are not defined as template", []])->once();112 $this->logger->shouldReceive('log')->withArgs([LogLevel::INFO, "[MW Purge] Start purge of orphan bases", []])->once();113 $this->logger->shouldReceive('log')->withArgs([LogLevel::INFO, "[MW Purge] End purge of orphan bases", []])->once();114 $this->logger->shouldReceive('log')->withArgs([LogLevel::INFO, "[MW Purge] Purge completed", []])->once();115 $this->logger->shouldReceive('log')->withArgs([LogLevel::INFO, "[MW Purge] x database(s) deleted", []])->once();116 $this->logger->shouldReceive('log')->withArgs([LogLevel::INFO, "[MW Purge] x table(s) deleted in central DB", []])->once();117 $this->logger->shouldReceive('log')->withArgs([LogLevel::INFO, "[MW Purge] 0 directories deleted", []])->once();118 }119 private function initDao(): void120 {121 $this->dao->shouldReceive('setLogger')->once();122 $this->dao->shouldReceive('getDeletedDatabasesCount')->andReturn('x')->once();123 $this->dao->shouldReceive('getDeletedTablesCount')->andReturn('x')->once();124 }125 public function testPurgeUsedServicesEmptyWikiForAllProjectsExceptTemplateTwoPurgeWhenEmpty(): void126 {127 $this->logger->shouldReceive('log')->withArgs([LogLevel::INFO, "[MW Purge] Start purge of used but empty mediawiki on projects which are not defined as template", []])->once();128 $this->logger->shouldReceive('log')->withArgs([LogLevel::INFO, "[MW Purge] Found candidate mediawiki_102", []])->once();129 $this->logger->shouldReceive('log')->withArgs([LogLevel::INFO, "[MW Purge] Found candidate mediawiki_103", []])->once();130 $this->logger->shouldReceive('log')->withArgs([LogLevel::INFO, "[MW Purge] Delete data dir", []])->twice();131 $this->dao->shouldReceive('getMediawikiDatabasesInUsedServices')132 ->andReturn(133 [134 [135 'project_id' => 101,136 'database_name' => 'mediawiki_101'137 ],138 [139 'project_id' => 102,140 'database_name' => 'mediawiki_102'141 ],142 [143 'project_id' => 103,144 'database_name' => 'mediawiki_103'145 ],146 ]147 );148 $this->dao->shouldReceive('getAllMediawikiBasesNotReferenced')->once()->andReturn([]);149 $this->project_2->shouldReceive("isTemplate")->once()->andReturnFalse();150 $this->project_3->shouldReceive("isTemplate")->once()->andReturnFalse();151 $this->data_dir->shouldReceive('getMediawikiDir')->withArgs([$this->project_2])->once()->andReturn("path/to/mediawiki_102");152 $this->data_dir->shouldReceive('getMediawikiDir')->withArgs([$this->project_3])->once()->andReturn("path/to/mediawiki_103");153 $this->dao->shouldReceive('desactivateService')->once()->withArgs([102, false]);154 $this->dao->shouldReceive('desactivateService')->once()->withArgs([103, false]);155 $this->media_wiki_dao->shouldReceive('getMediawikiPagesNumberOfAProject')156 ->with($this->project_1)157 ->once()158 ->andReturn(159 ['result' => 2]160 );161 $this->media_wiki_dao->shouldReceive('getMediawikiPagesNumberOfAProject')162 ->with($this->project_2)163 ->once()164 ->andReturn(165 ['result' => 0]166 );167 $this->media_wiki_dao->shouldReceive('getMediawikiPagesNumberOfAProject')168 ->with($this->project_3)169 ->once()170 ->andReturn(171 ['result' => 0]172 );173 $this->dao->shouldReceive('purge')->twice();174 $this->clean_unused->purge(false, [], true, null);175 }176 public function testPurgeUsedServicesEmptyWikiForAllProjectsExceptTemplateOnePurgeWhenEmptyWithOneTemplate(): void177 {178 $this->logger->shouldReceive('log')->withArgs([LogLevel::INFO, "[MW Purge] Start purge of used but empty mediawiki on projects which are not defined as template", []])->once();179 $this->logger->shouldReceive('log')->withArgs([LogLevel::INFO, "[MW Purge] Found candidate mediawiki_103", []])->once();180 $this->logger->shouldReceive('log')->withArgs([LogLevel::INFO, "[MW Purge] Delete data dir", []])->once();181 $this->logger->shouldReceive('log')->withArgs([LogLevel::WARNING, "[MW Purge] Project project_2 (102) is a template. Skipped.", []])->once();182 $this->dao->shouldReceive('getMediawikiDatabasesInUsedServices')183 ->once()184 ->andReturn(185 [186 [187 'project_id' => 101,188 'database_name' => 'mediawiki_101'189 ],190 [191 'project_id' => 102,192 'database_name' => 'mediawiki_102'193 ],194 [195 'project_id' => 103,196 'database_name' => 'mediawiki_103'197 ],198 ]199 );200 $this->dao->shouldReceive('getAllMediawikiBasesNotReferenced')->once()->andReturn([]);201 $this->project_2->shouldReceive("isTemplate")->once()->andReturn(true);202 $this->project_3->shouldReceive("isTemplate")->once()->andReturn(false);203 $this->data_dir->shouldReceive('getMediawikiDir')->withArgs([$this->project_3])->once()->andReturn("path/to/mediawiki_103");204 $this->dao->shouldReceive('desactivateService')->once()->withArgs([103, false]);205 $this->media_wiki_dao->shouldReceive('getMediawikiPagesNumberOfAProject')206 ->with($this->project_1)207 ->once()208 ->andReturn(['result' => 2]);209 $this->media_wiki_dao->shouldReceive('getMediawikiPagesNumberOfAProject')210 ->with($this->project_2)211 ->once()212 ->andReturn(['result' => 0]);213 $this->media_wiki_dao->shouldReceive('getMediawikiPagesNumberOfAProject')214 ->with($this->project_3)215 ->once()216 ->andReturn(['result' => 0]);217 $this->dao->shouldReceive('purge')->once();218 $this->clean_unused->purge(false, [], true, null);219 }220 public function testPurgeUsedServicesEmptyWikiForAllProjectsExceptTemplateOnePurgeWhenEmptyWithOneTemplateWithLimit(): void221 {222 $this->logger->shouldReceive('log')->withArgs([LogLevel::INFO, "[MW Purge] Start purge of 3 used but empty mediawiki on projects which are not defined as template", []])->once();223 $this->logger->shouldReceive('log')->withArgs([LogLevel::INFO, "[MW Purge] Found candidate mediawiki_103", []])->once();224 $this->logger->shouldReceive('log')->withArgs([LogLevel::INFO, "[MW Purge] Delete data dir", []])->once();225 $this->logger->shouldReceive('log')->withArgs([LogLevel::WARNING, "[MW Purge] Project project_2 (102) is a template. Skipped.", []])->once();226 $this->dao->shouldReceive('getMediawikiDatabasesInUsedServices')227 ->once()228 ->andReturn(229 [230 [231 'project_id' => 101,232 'database_name' => 'mediawiki_101'233 ],234 [235 'project_id' => 102,236 'database_name' => 'mediawiki_102'237 ],238 [239 'project_id' => 103,240 'database_name' => 'mediawiki_103'241 ],242 ]243 );244 $this->dao->shouldReceive('getAllMediawikiBasesNotReferenced')->once()->andReturn([]);245 $this->project_2->shouldReceive("isTemplate")->once()->andReturn(true);246 $this->project_3->shouldReceive("isTemplate")->once()->andReturn(false);247 $this->data_dir->shouldReceive('getMediawikiDir')->once()->withArgs([$this->project_3])->andReturn("path/to/mediawiki_103");248 $this->dao->shouldReceive('desactivateService')->once()->withArgs([103, false]);249 $this->media_wiki_dao->shouldReceive('getMediawikiPagesNumberOfAProject')250 ->with($this->project_1)251 ->once()252 ->andReturn(['result' => 2]);253 $this->media_wiki_dao->shouldReceive('getMediawikiPagesNumberOfAProject')254 ->with($this->project_2)255 ->once()256 ->andReturn(['result' => 0]);257 $this->media_wiki_dao->shouldReceive('getMediawikiPagesNumberOfAProject')258 ->with($this->project_3)259 ->once()260 ->andReturn(['result' => 0]);261 $this->dao->shouldReceive('purge')->once();262 $this->clean_unused->purge(false, [], true, 3);...

Full Screen

Full Screen

GuardTest.php

Source:GuardTest.php Github

copy

Full Screen

...30 public function test_attempt()31 {32 $config = $this->mock(DomainConfiguration::class);33 $config34 ->shouldReceive('get')->withArgs(['account_prefix'])->once()35 ->shouldReceive('get')->withArgs(['account_suffix'])->once()36 ->shouldReceive('get')->withArgs(['username'])->once()37 ->shouldReceive('get')->withArgs(['password'])->once();38 $ldap = $this->mock(Ldap::class);39 $ldap->shouldReceive('bind')->twice()->andReturn(true);40 $guard = new Guard($ldap, $config);41 $this->assertTrue($guard->attempt('username', 'password'));42 }43 public function test_bind_using_credentials()44 {45 $config = $this->mock(DomainConfiguration::class);46 $ldap = $this->mock(Ldap::class);47 $ldap->shouldReceive('bind')->once()->withArgs(['username', 'password'])->andReturn(true);48 $guard = new Guard($ldap, $config);49 $this->assertNull($guard->bind('username', 'password'));50 }51 public function test_bind_always_throws_exception_on_invalid_credentials()52 {53 $this->expectException(BindException::class);54 $config = $this->mock(DomainConfiguration::class);55 $ldap = $this->mock(Ldap::class);56 $ldap57 ->shouldReceive('bind')->once()->withArgs(['username', 'password'])->andReturn(false)58 ->shouldReceive('getLastError')->once()->andReturn('error')59 ->shouldReceive('getDetailedError')->once()->andReturn(new DetailedError(42, 'Invalid credentials', '80090308: LdapErr: DSID-0C09042A'))60 ->shouldReceive('errNo')->once()->andReturn(1);61 $guard = new Guard($ldap, $config);62 $guard->bind('username', 'password');63 }64 public function test_bind_as_administrator()65 {66 $config = $this->mock(DomainConfiguration::class);67 $config68 ->shouldReceive('get')->withArgs(['username'])->once()->andReturn('admin')69 ->shouldReceive('get')->withArgs(['password'])->once()->andReturn('password');70 $ldap = $this->mock(Ldap::class);71 $ldap->shouldReceive('bind')->once()->withArgs(['admin', 'password'])->andReturn(true);72 $guard = new Guard($ldap, $config);73 $this->assertNull($guard->bindAsAdministrator());74 }75 public function test_prefix_and_suffix_are_being_used_in_attempt()76 {77 $config = $this->mock(DomainConfiguration::class);78 $config79 ->shouldReceive('get')->withArgs(['account_prefix'])->once()->andReturn('prefix.')80 ->shouldReceive('get')->withArgs(['account_suffix'])->once()->andReturn('.suffix');81 $ldap = $this->mock(Ldap::class);82 $ldap->shouldReceive('bind')->once()->withArgs(['prefix.username.suffix', 'password'])->andReturn(true);83 $guard = new Guard($ldap, $config);84 $this->assertTrue($guard->attempt('username', 'password', $bindAsUser = true));85 }86 public function test_binding_events_are_fired_during_bind()87 {88 $ldap = $this->mock(Ldap::class);89 $ldap->shouldReceive('bind')->once()->withArgs(['johndoe', 'secret'])->andReturn(true);90 $events = new Dispatcher();91 $firedBinding = false;92 $firedBound = false;93 $events->listen(Binding::class, function (Binding $event) use (&$firedBinding) {94 $this->assertEquals($event->getUsername(), 'johndoe');95 $this->assertEquals($event->getPassword(), 'secret');96 $firedBinding = true;97 });98 $events->listen(Bound::class, function (Bound $event) use (&$firedBound) {99 $this->assertEquals($event->getUsername(), 'johndoe');100 $this->assertEquals($event->getPassword(), 'secret');101 $firedBound = true;102 });103 $guard = new Guard($ldap, new DomainConfiguration([]));104 $guard->setDispatcher($events);105 $guard->bind('johndoe', 'secret');106 $this->assertTrue($firedBinding);107 $this->assertTrue($firedBound);108 }109 public function test_auth_events_are_fired_during_attempt()110 {111 $config = $this->mock(DomainConfiguration::class);112 $config113 ->shouldReceive('get')->withArgs(['account_prefix'])->once()->andReturn('prefix.')114 ->shouldReceive('get')->withArgs(['account_suffix'])->once()->andReturn('.suffix');115 $ldap = $this->mock(Ldap::class);116 $ldap->shouldReceive('bind')->once()->withArgs(['prefix.johndoe.suffix', 'secret'])->andReturn(true);117 $events = new Dispatcher();118 $firedBinding = false;119 $firedBound = false;120 $firedAttempting = false;121 $firedPassed = false;122 $events->listen(Binding::class, function (Binding $event) use (&$firedBinding) {123 $this->assertEquals($event->getUsername(), 'prefix.johndoe.suffix');124 $this->assertEquals($event->getPassword(), 'secret');125 $firedBinding = true;126 });127 $events->listen(Bound::class, function (Bound $event) use (&$firedBound) {128 $this->assertEquals($event->getUsername(), 'prefix.johndoe.suffix');129 $this->assertEquals($event->getPassword(), 'secret');130 $firedBound = true;131 });132 $events->listen(Attempting::class, function (Attempting $event) use (&$firedAttempting) {133 $this->assertEquals($event->getUsername(), 'johndoe');134 $this->assertEquals($event->getPassword(), 'secret');135 $firedAttempting = true;136 });137 $events->listen(Passed::class, function (Passed $event) use (&$firedPassed) {138 $this->assertEquals($event->getUsername(), 'johndoe');139 $this->assertEquals($event->getPassword(), 'secret');140 $firedPassed = true;141 });142 $guard = new Guard($ldap, $config);143 $guard->setDispatcher($events);144 $this->assertTrue($guard->attempt('johndoe', 'secret', $bindAsUser = true));145 $this->assertTrue($firedBinding);146 $this->assertTrue($firedBound);147 $this->assertTrue($firedAttempting);148 $this->assertTrue($firedPassed);149 }150 public function test_all_auth_events_can_be_listened_to_with_wildcard()151 {152 $config = $this->mock(DomainConfiguration::class);153 $config154 ->shouldReceive('get')->withArgs(['account_prefix'])->once()->andReturn('prefix.')155 ->shouldReceive('get')->withArgs(['account_suffix'])->once()->andReturn('.suffix');156 $ldap = $this->mock(Ldap::class);157 $ldap->shouldReceive('bind')->once()->withArgs(['prefix.johndoe.suffix', 'secret'])->andReturn(true);158 $events = new Dispatcher();159 $totalFired = 0;160 $events->listen('Adldap\Auth\Events\*', function ($eventName) use (&$totalFired) {161 $totalFired++;162 });163 $guard = new Guard($ldap, $config);164 $guard->setDispatcher($events);165 $this->assertTrue($guard->attempt('johndoe', 'secret', $bindAsUser = true));166 $this->assertEquals($totalFired, 4);167 }168}...

Full Screen

Full Screen

withArgs

Using AI Code Generation

copy

Full Screen

1{2 public function __construct($arg1, $arg2)3 {4 $this->arg1 = $arg1;5 $this->arg2 = $arg2;6 }7 public function getArgs()8 {9 return $this->arg1 . ' ' . $this->arg2;10 }11}12$myClass = new myClass('Hello', 'World');13{14 public function __construct($arg1, $arg2)15 {16 $this->arg1 = $arg1;17 $this->arg2 = $arg2;18 }19 public function getArgs()20 {21 return $this->arg1 . ' ' . $this->arg2;22 }23}24$myClass = new myClass('Hello', 'World');25{26 public function __construct($arg1, $arg2)27 {28 $this->arg1 = $arg1;29 $this->arg2 = $arg2;30 }31 public function getArgs()32 {33 return $this->arg1 . ' ' . $this->arg2;34 }35}36$myClass = new myClass('Hello', 'World');37{38 public function __construct($arg1, $arg2)39 {40 $this->arg1 = $arg1;41 $this->arg2 = $arg2;42 }43 public function getArgs()44 {45 return $this->arg1 . ' ' . $this->arg2;46 }47}48$myClass = new myClass('Hello', 'World');49{50 public function __construct($arg1, $arg2)51 {52 $this->arg1 = $arg1;

Full Screen

Full Screen

withArgs

Using AI Code Generation

copy

Full Screen

1{2 public function withArgs($args)3 {4 $this->args = $args;5 return $this;6 }7 public function __call($name, $args)8 {9 if (is_callable($name)) {10 return call_user_func_array($name, array_merge($this->args, $args));11 }12 }13}14$are = new are();15$are->withArgs(array(1, 2, 3))->array_sum();16Your name to display (optional):

Full Screen

Full Screen

withArgs

Using AI Code Generation

copy

Full Screen

1require_once 'are.php';2$are = new Are();3$are->withArgs('1', '2', '3', '4', '5');4$are->withArgs('1', '2', '3', '4', '5', '6');5require_once 'is.php';6$is = new Is();7$is->withArgs('1', '2', '3', '4', '5');8$is->withArgs('1', '2', '3', '4', '5', '6');9require_once 'can.php';10$can = new Can();11$can->withArgs('1', '2', '3', '4', '5');12$can->withArgs('1', '2', '3', '4', '5', '6');13require_once 'will.php';14$will = new Will();15$will->withArgs('1', '2', '3', '4', '5');16$will->withArgs('1', '2', '3', '4', '5', '6');17require_once 'has.php';18$has = new Has();19$has->withArgs('1', '2', '3', '4', '5');20$has->withArgs('1', '2', '3', '4', '5', '6');21require_once 'would.php';22$would = new Would();23$would->withArgs('1', '2', '3', '4', '5');24$would->withArgs('1', '2', '3', '4', '5', '6');25require_once 'should.php';26$should = new Should();27$should->withArgs('1', '2', '3', '4', '5');28$should->withArgs('1', '2', '3', '4', '5', '6');29require_once 'could.php';30$could = new Could();31$could->withArgs('1', '2', '3', '4', '5');32$could->withArgs('1

Full Screen

Full Screen

withArgs

Using AI Code Generation

copy

Full Screen

1class are{2 public function withArgs($a){3 return $a;4 }5}6$obj = new are();7echo $obj->withArgs('hi');8class are{9 public function withArgs($a){10 return $a;11 }12}13$obj = new are();14echo $obj->withArgs('hi');15class are{16 public function withArgs($a){17 return $a;18 }19}20$obj = new are();21echo $obj->withArgs('hi');22class are{23 public function withArgs($a){24 return $a;25 }26}27$obj = new are();28echo $obj->withArgs('hi');29class are{30 public function withArgs($a){31 return $a;32 }33}34$obj = new are();35echo $obj->withArgs('hi');36class are{37 public function withArgs($a){38 return $a;39 }40}41$obj = new are();42echo $obj->withArgs('hi');43class are{44 public function withArgs($a){45 return $a;46 }47}48$obj = new are();49echo $obj->withArgs('hi');50class are{51 public function withArgs($a){52 return $a;53 }54}55$obj = new are();56echo $obj->withArgs('hi');57class are{58 public function withArgs($a){59 return $a;60 }61}62$obj = new are();63echo $obj->withArgs('hi');

Full Screen

Full Screen

withArgs

Using AI Code Generation

copy

Full Screen

1class are{2 public function withArgs($arg1,$arg2,$arg3){3 echo $arg1;4 echo $arg2;5 echo $arg3;6 }7}8$are = new are();9$are->withArgs(1,2,3);10Related Posts: PHP | ReflectionMethod::getStaticVariables() Method11PHP | ReflectionMethod::getNumberOfParameters() Method12PHP | ReflectionMethod::getNumberOfRequiredParameters() Method13PHP | ReflectionMethod::getParameters() Method14PHP | ReflectionMethod::getReturnType() Method15PHP | ReflectionMethod::getClosure() Method16PHP | ReflectionMethod::isGenerator() Method17PHP | ReflectionMethod::isVariadic() Method18PHP | ReflectionMethod::getModifiers() Method19PHP | ReflectionMethod::isConstructor() Method20PHP | ReflectionMethod::isDestructor() Method21PHP | ReflectionMethod::isAbstract() Method22PHP | ReflectionMethod::isFinal() Method23PHP | ReflectionMethod::isPrivate() Method24PHP | ReflectionMethod::isProtected() Method25PHP | ReflectionMethod::isPublic() Method26PHP | ReflectionMethod::isStatic() Method27PHP | ReflectionMethod::isUserDefined() Method28PHP | ReflectionMethod::getDeclaringClass() Method29PHP | ReflectionMethod::getPrototype() Method

Full Screen

Full Screen

withArgs

Using AI Code Generation

copy

Full Screen

1if (php_sapi_name() == 'cli') {2 $args = array_slice($argv, 1);3 $args = are::withArgs($args);4 if ($args->has('name')) {5 echo "Hello " . $args->get('name');6 } else {7 echo "Hello World";8 }9} else {10 echo "Hello World";11}12if (php_sapi_name() == 'cli') {13 $args = array_slice($argv, 1);14 $args = are::withArgs($args);15 if ($args->has('name')) {16 echo "Hello " . $args->get('name');17 } else {18 echo "Hello World";19 }20} else {21 echo "Hello World";22}23if (php_sapi_name() == 'cli') {24 $args = array_slice($argv, 1);25 $args = are::withArgs($args);26 if ($args->has('name')) {27 echo "Hello " . $args->get('name');28 } else {29 echo "Hello World";30 }31} else {32 echo "Hello World";33}34if (php_sapi_name() == 'cli') {35 $args = array_slice($argv, 1);36 $args = are::withArgs($args);37 if ($args->has('name')) {38 echo "Hello " . $args->get('name');39 } else {40 echo "Hello World";41 }42} else {43 echo "Hello World";44}45if (php_sapi_name() == 'cli') {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful