├── .codecov.yml ├── .editorconfig ├── .github └── pull_request_template.md ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── composer.json ├── doc ├── CodingStyle.md └── ContributorRules.md ├── src ├── Client.php ├── ClientState.php ├── Constant │ ├── AccessTokenStatus.php │ ├── ConflictBehavior.php │ ├── DriveType.php │ ├── FolderViewSortBy.php │ ├── FolderViewSortOrder.php │ ├── FolderViewType.php │ ├── PackageType.php │ ├── QuotaStatus.php │ ├── Role.php │ ├── SharedScope.php │ ├── SharingLinkScope.php │ ├── SharingLinkType.php │ └── SpecialFolderName.php ├── Definition │ ├── OperationDefinition.php │ ├── OperationDefinitionInterface.php │ ├── Parameter │ │ ├── AbstractParameterDefinition.php │ │ ├── BodyParameterDefinition.php │ │ ├── HeaderParameterDefinition.php │ │ ├── ParameterDefinitionInterface.php │ │ └── QueryStringParameterDefinition.php │ ├── ResourceDefinition.php │ ├── ResourceDefinitionInterface.php │ ├── ServiceDefinition.php │ └── ServiceDefinitionInterface.php ├── Exception │ └── ConflictException.php ├── Onedrive.php ├── Parameter │ ├── Injector │ │ ├── FlatInjector.php │ │ ├── HierarchicalInjector.php │ │ └── InjectorInterface.php │ ├── ParameterBuilder.php │ ├── ParameterBuilderInterface.php │ ├── ParameterDefinitionCollection.php │ └── ParameterDefinitionCollectionInterface.php ├── Proxy │ ├── AudioProxy.php │ ├── BaseItemProxy.php │ ├── BaseItemVersionProxy.php │ ├── DeletedProxy.php │ ├── DirectoryObjectProxy.php │ ├── DriveItemProxy.php │ ├── DriveItemVersionProxy.php │ ├── DriveProxy.php │ ├── EntityProxy.php │ ├── FileProxy.php │ ├── FileSystemInfoProxy.php │ ├── FolderProxy.php │ ├── FolderViewProxy.php │ ├── GeoCoordinatesProxy.php │ ├── GraphListProxy.php │ ├── HashesProxy.php │ ├── IdentityProxy.php │ ├── IdentitySetProxy.php │ ├── ImageProxy.php │ ├── ItemReferenceProxy.php │ ├── ListItemProxy.php │ ├── PackageProxy.php │ ├── PermissionProxy.php │ ├── PhotoProxy.php │ ├── PublicationFacetProxy.php │ ├── QuotaProxy.php │ ├── RemoteItemProxy.php │ ├── RootProxy.php │ ├── SearchResultProxy.php │ ├── SharedProxy.php │ ├── SharepointIdsProxy.php │ ├── SharingLinkProxy.php │ ├── SpecialFolderProxy.php │ ├── SystemFacetProxy.php │ ├── ThumbnailProxy.php │ ├── UploadSessionProxy.php │ ├── UserProxy.php │ ├── VideoProxy.php │ └── WorkbookProxy.php └── Serializer │ ├── OrderBySerializer.php │ ├── ScalarSerializer.php │ └── SerializerInterface.php └── test ├── functional ├── .gitignore ├── ClientTest.php ├── KrizalysOnedriveTest.php ├── Proxy │ ├── DriveItemProxyTest.php │ └── DriveProxyTest.php ├── Router.php ├── Traits │ ├── AssertionsTrait.php │ ├── AsynchronousTrait.php │ ├── ClientFactoryTrait.php │ ├── ConfigurationTrait.php │ ├── HttpJsonTrait.php │ ├── MicrosoftOauthAuthenticationTrait.php │ ├── OauthAuthorizationTrait.php │ ├── OnedriveSandboxTrait.php │ ├── ProcessTrait.php │ └── WebdriverTrait.php ├── bootstrap.php └── config.php.dist ├── phpunit.xml.dist └── unit ├── ClientTest.php ├── Definition ├── OperationDefinitionTest.php ├── Parameter │ └── AbstractParameterDefinitionTest.php ├── ResourceDefinitionTest.php └── ServiceDefinitionTest.php ├── Parameter ├── Injector │ ├── FlatInjectorTest.php │ └── HierarchicalInjectorTest.php ├── ParameterBuilderTest.php └── ParameterDefinitionCollectionTest.php ├── Proxy ├── AudioProxyTest.php ├── BaseItemProxyTest.php ├── DriveItemProxyTest.php ├── DriveProxyTest.php ├── EntityProxyTest.php ├── FileProxyTest.php ├── FileSystemInfoProxyTest.php ├── FolderProxyTest.php ├── FolderViewProxyTest.php ├── HashesProxyTest.php ├── IdentityProxyTest.php ├── IdentitySetProxyTest.php ├── ImageProxyTest.php ├── ItemReferenceProxyTest.php ├── PackageProxyTest.php ├── PhotoProxyTest.php ├── QuotaProxyTest.php ├── RemoteItemProxyTest.php ├── SharedProxyTest.php ├── SharepointIdsProxyTest.php ├── SharingLinkProxyTest.php ├── SpecialFolderProxyTest.php ├── UploadSessionProxyTest.php └── VideoProxyTest.php ├── Serializer ├── OrderBySerializerTest.php └── ScalarSerializerTest.php ├── bootstrap.php └── functions.php /.codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | status: 3 | project: no 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 4 7 | indent_style = space 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | Thanks for your pull request! 2 | 3 | Before we consider merging it, please take the time to ensure you are complying with these guidelines: 4 | 5 | * [ ] I have described my changes in the [CHANGELOG](https://github.com/krizalys/onedrive-php-sdk/blob/master/CHANGELOG.md) 6 | * [ ] I have adopted the [coding style](https://github.com/krizalys/onedrive-php-sdk/tree/master/doc/CodingStyle.md) 7 | * [ ] I have followed the [contributor rules](https://github.com/krizalys/onedrive-php-sdk/tree/master/doc/ContributorRules.md) 8 | * [ ] I have added consistent [PHPDoc](https://www.phpdoc.org/) documentation to symbols I added 9 | * [ ] I have fixed an issue and I added [unit test case(s)](https://github.com/krizalys/onedrive-php-sdk/tree/master/test/unit) 10 | * [ ] I have added a feature and I added [functional test case(s)](https://github.com/krizalys/onedrive-php-sdk/tree/master/test/functional) 11 | * [ ] I have passed all continuous integration checks or discussed with project maintainers of special treatments for exceptional cases 12 | * [ ] I accept my contribution to be code-reviewed by project maintainers and will refine it as requested 13 | * [ ] I accept my pull request to be rejected at the project maintainers' discretion, **even if it complies with all the above guidelines** 14 | 15 | **Failure to comply with the above guidelines will lead to your pull request being either modified for compliance, ignored until modified for compliance, and/or rejected altogether.** 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | composer.lock 3 | coverage.xml 4 | phpunit.xml 5 | .phpunit.result.cache 6 | 7 | # Mac OS X artifacts 8 | .DS_Store 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - '7.3' 5 | - '7.4' 6 | - '8.0' 7 | - '8.1' 8 | - '8.2' 9 | 10 | dist: bionic 11 | 12 | env: 13 | global: 14 | - XDEBUG_MODE=coverage 15 | 16 | before_install: composer install 17 | 18 | script: composer test:unit:coverage 19 | 20 | after_success: 21 | - 'curl --silent https://codecov.io/bash | bash' 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2008-2023, Krizalys 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "krizalys/onedrive-php-sdk", 3 | "description": "OneDrive SDK for PHP.", 4 | "homepage": "https://github.com/krizalys/onedrive-php-sdk", 5 | "license": "BSD-3-Clause", 6 | "prefer-stable": true, 7 | "keywords": [ 8 | "krizalys", 9 | "onedrive", 10 | "php", 11 | "sdk" 12 | ], 13 | "authors": [ 14 | { 15 | "name": "Christophe Vidal", 16 | "homepage": "http://www.krizalys.com/" 17 | } 18 | ], 19 | "support": { 20 | "email": "support@krizalys.com", 21 | "issues": "https://github.com/krizalys/onedrive-php-sdk/issues", 22 | "wiki": "https://github.com/krizalys/onedrive-php-sdk/wiki", 23 | "source": "https://github.com/krizalys/onedrive-php-sdk" 24 | }, 25 | "require": { 26 | "php": "^7.3 | ^8.0", 27 | "guzzlehttp/guzzle": ">=6.3.3", 28 | "guzzlehttp/psr7": "^1.7 | ^2.4", 29 | "microsoft/microsoft-graph": "^1.7.0" 30 | }, 31 | "require-dev": { 32 | "brianium/paratest": "^6.0.0", 33 | "php-webdriver/webdriver": "^1.7.0", 34 | "phpunit/phpunit": "^9.0.0", 35 | "symfony/process": "^4.0.0" 36 | }, 37 | "autoload": { 38 | "psr-4": { 39 | "Krizalys\\Onedrive\\": "src/" 40 | } 41 | }, 42 | "scripts": { 43 | "test:functional": "vendor/bin/phpunit --configuration test --testsuite 'Functional tests' --bootstrap test/functional/bootstrap.php", 44 | "test:functional:parallel": "vendor/bin/paratest --functional --configuration test --testsuite 'Functional tests' --bootstrap test/functional/bootstrap.php test/functional/KrizalysOnedriveTest.php & vendor/bin/paratest --functional --configuration test --testsuite 'Functional tests' --bootstrap test/functional/bootstrap.php test/functional/ClientTest.php & vendor/bin/paratest --functional --configuration test --testsuite 'Functional tests' --bootstrap test/functional/bootstrap.php test/functional/Proxy/DriveProxyTest.php & vendor/bin/paratest --functional --configuration test --testsuite 'Functional tests' --bootstrap test/functional/bootstrap.php test/functional/Proxy/DriveItemProxyTest.php & wait", 45 | "test:unit": "vendor/bin/phpunit --configuration test --testsuite 'Unit tests' --bootstrap test/unit/bootstrap.php", 46 | "test:unit:coverage": "vendor/bin/phpunit --configuration test --testsuite 'Unit tests' --bootstrap test/unit/bootstrap.php --coverage-clover coverage.xml", 47 | "test:unit:coverage:parallel": "vendor/bin/paratest --configuration test --testsuite 'Unit tests' --bootstrap test/unit/bootstrap.php --coverage-clover coverage.xml", 48 | "test:unit:parallel": "vendor/bin/paratest --configuration test --testsuite 'Unit tests' --bootstrap test/unit/bootstrap.php" 49 | }, 50 | "config": { 51 | "platform": { 52 | "ext-zip": "1.12.5" 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /doc/CodingStyle.md: -------------------------------------------------------------------------------- 1 | Coding style 2 | ============ 3 | 4 | This project uses a slighly modified variant of the [Symfony Coding 5 | Standards][symfony-coding-standards]. [StyleCI][style-ci] is used to enforce 6 | them. 7 | 8 | When in doubt, check out the StyleCI configuration, or fall back to the coding 9 | style used elsewhere in the codebase. 10 | 11 | [style-ci]: https://github.styleci.io/repos/23994489 12 | [symfony-coding-standards]: https://symfony.com/doc/current/contributing/code/standards.html 13 | -------------------------------------------------------------------------------- /doc/ContributorRules.md: -------------------------------------------------------------------------------- 1 | Contributor rules 2 | ================= 3 | 4 | This project expects any contributor to follow these rules, along with their 5 | rationale. 6 | 7 | | Rule | Rationale | 8 | | ------------------------------------------------------ | -------------------------------------- | 9 | | Verify that stubbed methods are called via `expects()` | Helps detecting unused stubbed methods | 10 | -------------------------------------------------------------------------------- /src/ClientState.php: -------------------------------------------------------------------------------- 1 | redirectUri; 61 | 62 | case 'token': 63 | return $this->token; 64 | } 65 | } 66 | 67 | /** 68 | * Setter. 69 | * 70 | * @param string $name 71 | * The name. 72 | * 73 | * @param mixed $value 74 | * The value. 75 | * 76 | * @since 3.0.0 77 | */ 78 | public function __set($name, $value) 79 | { 80 | switch ($name) { 81 | case 'redirectUri': 82 | $this->redirectUri = $value; 83 | break; 84 | 85 | case 'token': 86 | $this->token = $value; 87 | break; 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/Constant/AccessTokenStatus.php: -------------------------------------------------------------------------------- 1 | 1", incrementing the 43 | * trailing number until an available file name is discovered. 44 | * 45 | * @since 2.4.1 46 | * 47 | * @api 48 | */ 49 | const RENAME = 'rename'; 50 | 51 | /** 52 | * @var string 53 | * Replace behavior: replace the drive item if it already exists. 54 | * 55 | * @since 2.4.1 56 | * 57 | * @api 58 | */ 59 | const REPLACE = 'replace'; 60 | } 61 | -------------------------------------------------------------------------------- /src/Constant/DriveType.php: -------------------------------------------------------------------------------- 1 | bodyParameterDefinitions = $bodyParameterDefinitions; 70 | $this->headerParameterDefinitions = $headerParameterDefinitions; 71 | $this->queryStringParameterDefinitions = $queryStringParameterDefinitions; 72 | } 73 | 74 | /** 75 | * {@inheritDoc} 76 | * 77 | * Gets the body parameter definitions. 78 | * 79 | * @return \Krizalys\Onedrive\Parameter\ParameterDefinitionCollectionInterface 80 | * The body parameter definitions. 81 | * 82 | * @since 2.5.0 83 | */ 84 | public function getBodyParameterDefinitions() 85 | { 86 | return $this->bodyParameterDefinitions; 87 | } 88 | 89 | /** 90 | * {@inheritDoc} 91 | * 92 | * Gets the header parameter definitions. 93 | * 94 | * @return \Krizalys\Onedrive\Parameter\ParameterDefinitionCollectionInterface 95 | * The header parameter definitions. 96 | * 97 | * @since 2.5.0 98 | */ 99 | public function getHeaderParameterDefinitions() 100 | { 101 | return $this->headerParameterDefinitions; 102 | } 103 | 104 | /** 105 | * {@inheritDoc} 106 | * 107 | * @return \Krizalys\Onedrive\Parameter\ParameterDefinitionCollectionInterface 108 | * The query string parameter definitions. 109 | * 110 | * @since 2.5.0 111 | */ 112 | public function getQueryStringParameterDefinitions() 113 | { 114 | return $this->queryStringParameterDefinitions; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/Definition/OperationDefinitionInterface.php: -------------------------------------------------------------------------------- 1 | injector = $injector; 56 | $this->serializer = $serializer; 57 | } 58 | 59 | /** 60 | * {@inheritDoc} 61 | * 62 | * @param mixed $value 63 | * The value to serialize. 64 | * 65 | * @return string 66 | * The serialized value. 67 | * 68 | * @since 2.3.0 69 | */ 70 | public function serializeValue($value) 71 | { 72 | return $this->serializer->serialize($value); 73 | } 74 | 75 | /** 76 | * {@inheritDoc} 77 | * 78 | * @param mixed[string] $values 79 | * The array of values. 80 | * @param mixed $value 81 | * The value to inject. 82 | * 83 | * @return mixed[string] 84 | * The resulting array of values. 85 | * 86 | * @since 2.4.0 87 | */ 88 | public function injectValue(array $values, $value) 89 | { 90 | return $this->injector->inject($values, $value); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/Definition/Parameter/BodyParameterDefinition.php: -------------------------------------------------------------------------------- 1 | operationDefinitions = $operationDefinitions; 54 | $this->resourceDefinitions = $resourceDefinitions; 55 | } 56 | 57 | /** 58 | * {@inheritDoc} 59 | * 60 | * @param string $name 61 | * The name. 62 | * 63 | * @return \Krizalys\Onedrive\Definition\OperationDefinitionInterface 64 | * The operation definition. 65 | * 66 | * @since 2.5.0 67 | */ 68 | public function getOperationDefinition($name) 69 | { 70 | return $this->operationDefinitions[$name]; 71 | } 72 | 73 | /** 74 | * {@inheritDoc} 75 | * 76 | * @param string $name 77 | * The name. 78 | * 79 | * @return \Krizalys\Onedrive\Definition\ResourceDefinitionInterface 80 | * The resource definition. 81 | * 82 | * @since 2.5.0 83 | */ 84 | public function getResourceDefinition($name) 85 | { 86 | return $this->resourceDefinitions[$name]; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/Definition/ResourceDefinitionInterface.php: -------------------------------------------------------------------------------- 1 | resourceDefinitions = $resourceDefinitions; 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | * 48 | * @param string $name 49 | * The name. 50 | * 51 | * @return \Krizalys\Onedrive\Definition\ResourceDefinitionInterface 52 | * The resource definition. 53 | * 54 | * @since 2.5.0 55 | */ 56 | public function getResourceDefinition($name) 57 | { 58 | return $this->resourceDefinitions[$name]; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Definition/ServiceDefinitionInterface.php: -------------------------------------------------------------------------------- 1 | name = $name; 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | * 48 | * @param mixed[string] $values 49 | * The array of values. 50 | * @param mixed $value 51 | * The value to inject. 52 | * 53 | * @return mixed[string] 54 | * The resulting array of values. 55 | * 56 | * @since 2.4.0 57 | */ 58 | public function inject(array $values, $value) 59 | { 60 | return $values + [ 61 | $this->name => $value, 62 | ]; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Parameter/Injector/HierarchicalInjector.php: -------------------------------------------------------------------------------- 1 | path = $path; 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | * 48 | * @param mixed[string] $values 49 | * The array of values. 50 | * @param mixed $value 51 | * The value to inject. 52 | * 53 | * @return mixed[string] 54 | * The resulting array of values. 55 | * 56 | * @throws \Exception 57 | * Thrown if the path is empty. 58 | * 59 | * @since 2.4.0 60 | */ 61 | public function inject(array $values, $value) 62 | { 63 | if (empty($this->path)) { 64 | throw new \Exception('A hierarchical injector path cannot be empty'); 65 | } 66 | 67 | $keys = array_reverse($this->path); 68 | $key = array_shift($keys); 69 | 70 | $root = [ 71 | $key => $value, 72 | ]; 73 | 74 | foreach ($keys as $key) { 75 | $root = [ 76 | $key => $root, 77 | ]; 78 | } 79 | 80 | return array_replace_recursive($values, $root); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Parameter/Injector/InjectorInterface.php: -------------------------------------------------------------------------------- 1 | $def) { 45 | $value = $options[$key]; 46 | $value = $def->serializeValue($value); 47 | $opts = $def->injectValue($opts, $value); 48 | } 49 | 50 | return $opts; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Parameter/ParameterBuilderInterface.php: -------------------------------------------------------------------------------- 1 | parameterBuilder = $parameterBuilder; 53 | $this->parameterDefinitions = $parameterDefinitions; 54 | } 55 | 56 | /** 57 | * {@inheritDoc} 58 | * 59 | * @param mixed[string] $options 60 | * The options. 61 | * 62 | * @return mixed[string] 63 | * The options. 64 | * 65 | * @since 2.5.0 66 | */ 67 | public function buildOptions(array $options) 68 | { 69 | return $this 70 | ->parameterBuilder 71 | ->build($this->parameterDefinitions, $options); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Parameter/ParameterDefinitionCollectionInterface.php: -------------------------------------------------------------------------------- 1 | entity; 95 | 96 | switch ($name) { 97 | case 'album': 98 | return $audio->getAlbum(); 99 | 100 | case 'albumArtist': 101 | return $audio->getAlbumArtist(); 102 | 103 | case 'artist': 104 | return $audio->getArtist(); 105 | 106 | case 'bitrate': 107 | return $audio->getBitrate(); 108 | 109 | case 'composers': 110 | return $audio->getComposers(); 111 | 112 | case 'copyright': 113 | return $audio->getCopyright(); 114 | 115 | case 'disc': 116 | return $audio->getDisc(); 117 | 118 | case 'discCount': 119 | return $audio->getDiscCount(); 120 | 121 | case 'duration': 122 | return $audio->getDuration(); 123 | 124 | case 'genre': 125 | return $audio->getGenre(); 126 | 127 | case 'hasDrm': 128 | return $audio->getHasDrm(); 129 | 130 | case 'isVariableBitrate': 131 | return $audio->getIsVariableBitrate(); 132 | 133 | case 'title': 134 | return $audio->getTitle(); 135 | 136 | case 'track': 137 | return $audio->getTrack(); 138 | 139 | case 'trackCount': 140 | return $audio->getTrackCount(); 141 | 142 | case 'year': 143 | return $audio->getYear(); 144 | 145 | default: 146 | return parent::__get($name); 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/Proxy/BaseItemProxy.php: -------------------------------------------------------------------------------- 1 | entity; 85 | 86 | switch ($name) { 87 | case 'createdBy': 88 | $createdBy = $baseItem->getCreatedBy(); 89 | return $createdBy !== null ? new IdentitySetProxy($this->graph, $createdBy) : null; 90 | 91 | case 'createdDateTime': 92 | return $baseItem->getCreatedDateTime(); 93 | 94 | case 'description': 95 | return $baseItem->getDescription(); 96 | 97 | case 'eTag': 98 | return $baseItem->getETag(); 99 | 100 | case 'lastModifiedBy': 101 | $lastModifiedBy = $baseItem->getLastModifiedBy(); 102 | return $lastModifiedBy !== null ? new IdentitySetProxy($this->graph, $lastModifiedBy) : null; 103 | 104 | case 'lastModifiedDateTime': 105 | return $baseItem->getLastModifiedDateTime(); 106 | 107 | case 'name': 108 | return $baseItem->getName(); 109 | 110 | case 'parentReference': 111 | $parentReference = $baseItem->getParentReference(); 112 | return $parentReference !== null ? new ItemReferenceProxy($this->graph, $parentReference) : null; 113 | 114 | case 'webUrl': 115 | return $baseItem->getWebUrl(); 116 | 117 | case 'createdByUser': 118 | $createdByUser = $baseItem->getCreatedByUser(); 119 | return $createdByUser !== null ? new UserProxy($this->graph, $createdByUser) : null; 120 | 121 | case 'lastModifiedByUser': 122 | $lastModifiedByUser = $baseItem->getLastModifiedByUser(); 123 | return $lastModifiedByUser !== null ? new UserProxy($this->graph, $lastModifiedByUser) : null; 124 | 125 | default: 126 | return parent::__get($name); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/Proxy/BaseItemVersionProxy.php: -------------------------------------------------------------------------------- 1 | graph = $graph; 61 | $this->entity = $entity; 62 | } 63 | 64 | /** 65 | * Getter. 66 | * 67 | * @param string $name 68 | * The name. 69 | * 70 | * @return mixed 71 | * The value. 72 | * 73 | * @since 2.0.0 74 | */ 75 | public function __get($name) 76 | { 77 | switch ($name) { 78 | case 'id': 79 | return $this->entity->getId(); 80 | 81 | default: 82 | throw new \Exception("Undefined property: $name"); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Proxy/FileProxy.php: -------------------------------------------------------------------------------- 1 | entity; 67 | 68 | switch ($name) { 69 | case 'hashes': 70 | $hashes = $file->getHashes(); 71 | return $hashes !== null ? new HashesProxy($this->graph, $hashes) : null; 72 | 73 | case 'mimeType': 74 | return $file->getMimeType(); 75 | 76 | default: 77 | return parent::__get($name); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Proxy/FileSystemInfoProxy.php: -------------------------------------------------------------------------------- 1 | entity; 69 | 70 | switch ($name) { 71 | case 'createdDateTime': 72 | return $fileSystemInfo->getCreatedDateTime(); 73 | 74 | case 'lastAccessedDateTime': 75 | return $fileSystemInfo->getLastAccessedDateTime(); 76 | 77 | case 'lastModifiedDateTime': 78 | return $fileSystemInfo->getLastModifiedDateTime(); 79 | 80 | default: 81 | return parent::__get($name); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Proxy/FolderProxy.php: -------------------------------------------------------------------------------- 1 | entity; 67 | 68 | switch ($name) { 69 | case 'childCount': 70 | return $folder->getChildCount(); 71 | 72 | case 'view': 73 | $view = $folder->getView(); 74 | return $view !== null ? new FolderViewProxy($this->graph, $view) : null; 75 | 76 | default: 77 | return parent::__get($name); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Proxy/FolderViewProxy.php: -------------------------------------------------------------------------------- 1 | entity; 69 | 70 | switch ($name) { 71 | case 'sortBy': 72 | return $folderView->getSortBy(); 73 | 74 | case 'sortOrder': 75 | return $folderView->getSortOrder(); 76 | 77 | case 'viewType': 78 | return $folderView->getViewType(); 79 | 80 | default: 81 | return parent::__get($name); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Proxy/GeoCoordinatesProxy.php: -------------------------------------------------------------------------------- 1 | entity; 69 | 70 | switch ($name) { 71 | case 'crc32Hash': 72 | return $hashes->getCrc32Hash(); 73 | 74 | case 'quickXorHash': 75 | return $hashes->getQuickXorHash(); 76 | 77 | case 'sha1Hash': 78 | return $hashes->getSha1Hash(); 79 | 80 | default: 81 | return parent::__get($name); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Proxy/IdentityProxy.php: -------------------------------------------------------------------------------- 1 | entity; 65 | 66 | switch ($name) { 67 | case 'displayName': 68 | return $identity->getDisplayName(); 69 | 70 | default: 71 | return parent::__get($name); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Proxy/IdentitySetProxy.php: -------------------------------------------------------------------------------- 1 | entity; 69 | 70 | switch ($name) { 71 | case 'application': 72 | $application = $identitySet->getApplication(); 73 | return $application !== null ? new IdentityProxy($this->graph, $application) : null; 74 | 75 | case 'device': 76 | $device = $identitySet->getDevice(); 77 | return $device !== null ? new IdentityProxy($this->graph, $device) : null; 78 | 79 | case 'user': 80 | $user = $identitySet->getUser(); 81 | return $user !== null ? new IdentityProxy($this->graph, $user) : null; 82 | 83 | default: 84 | return parent::__get($name); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/Proxy/ImageProxy.php: -------------------------------------------------------------------------------- 1 | entity; 67 | 68 | switch ($name) { 69 | case 'height': 70 | return $image->getHeight(); 71 | 72 | case 'width': 73 | return $image->getWidth(); 74 | 75 | default: 76 | return parent::__get($name); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/Proxy/ItemReferenceProxy.php: -------------------------------------------------------------------------------- 1 | entity; 71 | 72 | switch ($name) { 73 | case 'id': 74 | return $itemReference->getId(); 75 | 76 | case 'driveId': 77 | return $itemReference->getDriveId(); 78 | 79 | case 'driveType': 80 | return $itemReference->getDriveType(); 81 | 82 | case 'path': 83 | return $itemReference->getPath(); 84 | 85 | default: 86 | return parent::__get($name); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/Proxy/ListItemProxy.php: -------------------------------------------------------------------------------- 1 | entity; 65 | 66 | switch ($name) { 67 | case 'type': 68 | return $package->getType(); 69 | 70 | default: 71 | return parent::__get($name); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Proxy/PermissionProxy.php: -------------------------------------------------------------------------------- 1 | entity; 65 | 66 | /** 67 | * @todo Support all properties. 68 | */ 69 | switch ($name) { 70 | case 'link': 71 | $link = $permission->getLink(); 72 | return $link !== null ? new SharingLinkProxy($this->graph, $link) : null; 73 | 74 | default: 75 | return parent::__get($name); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Proxy/PhotoProxy.php: -------------------------------------------------------------------------------- 1 | entity; 79 | 80 | switch ($name) { 81 | case 'cameraMake': 82 | return $photo->getCameraMake(); 83 | 84 | case 'cameraModel': 85 | return $photo->getCameraModel(); 86 | 87 | case 'exposureDenominator': 88 | return $photo->getExposureDenominator(); 89 | 90 | case 'exposureNumerator': 91 | return $photo->getExposureNumerator(); 92 | 93 | case 'fNumber': 94 | return $photo->getFNumber(); 95 | 96 | case 'focalLength': 97 | return $photo->getFocalLength(); 98 | 99 | case 'iso': 100 | return $photo->getIso(); 101 | 102 | case 'takenDateTime': 103 | return $photo->getTakenDateTime(); 104 | 105 | default: 106 | return parent::__get($name); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/Proxy/PublicationFacetProxy.php: -------------------------------------------------------------------------------- 1 | entity; 73 | 74 | switch ($name) { 75 | case 'deleted': 76 | return $quota->getDeleted(); 77 | 78 | case 'remaining': 79 | return $quota->getRemaining(); 80 | 81 | case 'state': 82 | return $quota->getState(); 83 | 84 | case 'total': 85 | return $quota->getTotal(); 86 | 87 | case 'used': 88 | return $quota->getUsed(); 89 | 90 | default: 91 | return parent::__get($name); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/Proxy/RootProxy.php: -------------------------------------------------------------------------------- 1 | entity; 71 | 72 | switch ($name) { 73 | case 'owner': 74 | $owner = $shared->getOwner(); 75 | return $owner !== null ? new IdentitySetProxy($this->graph, $owner) : null; 76 | 77 | case 'scope': 78 | return $shared->getScope(); 79 | 80 | case 'sharedBy': 81 | $sharedBy = $shared->getSharedBy(); 82 | return $sharedBy !== null ? new IdentitySetProxy($this->graph, $sharedBy) : null; 83 | 84 | case 'sharedDateTime': 85 | return $shared->getSharedDateTime(); 86 | 87 | default: 88 | return parent::__get($name); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/Proxy/SharepointIdsProxy.php: -------------------------------------------------------------------------------- 1 | entity; 75 | 76 | switch ($name) { 77 | case 'listId': 78 | return $sharepointIds->getListId(); 79 | 80 | case 'listItemId': 81 | return $sharepointIds->getListItemId(); 82 | 83 | case 'listItemUniqueId': 84 | return $sharepointIds->getListItemUniqueId(); 85 | 86 | case 'siteId': 87 | return $sharepointIds->getSiteId(); 88 | 89 | case 'siteUrl': 90 | return $sharepointIds->getSiteUrl(); 91 | 92 | case 'webId': 93 | return $sharepointIds->getWebId(); 94 | 95 | default: 96 | return parent::__get($name); 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/Proxy/SharingLinkProxy.php: -------------------------------------------------------------------------------- 1 | entity; 71 | 72 | switch ($name) { 73 | case 'application': 74 | $application = $sharingLink->getApplication(); 75 | return $application !== null ? new IdentityProxy($this->graph, $application) : null; 76 | 77 | case 'scope': 78 | return $sharingLink->getScope(); 79 | 80 | case 'type': 81 | return $sharingLink->getType(); 82 | 83 | case 'webUrl': 84 | return $sharingLink->getWebUrl(); 85 | 86 | default: 87 | return parent::__get($name); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/Proxy/SpecialFolderProxy.php: -------------------------------------------------------------------------------- 1 | entity; 65 | 66 | switch ($name) { 67 | case 'name': 68 | return $specialFolder->getName(); 69 | 70 | default: 71 | return parent::__get($name); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Proxy/SystemFacetProxy.php: -------------------------------------------------------------------------------- 1 | entity; 83 | 84 | switch ($name) { 85 | case 'audioBitsPerSample': 86 | return $video->getAudioBitsPerSample(); 87 | 88 | case 'audioChannels': 89 | return $video->getAudioChannels(); 90 | 91 | case 'audioFormat': 92 | return $video->getAudioFormat(); 93 | 94 | case 'audioSamplesPerSecond': 95 | return $video->getAudioSamplesPerSecond(); 96 | 97 | case 'bitrate': 98 | return $video->getBitrate(); 99 | 100 | case 'duration': 101 | return $video->getDuration(); 102 | 103 | case 'fourCc': 104 | return $video->getFourCC(); 105 | 106 | case 'frameRate': 107 | return $video->getFrameRate(); 108 | 109 | case 'height': 110 | return $video->getHeight(); 111 | 112 | case 'width': 113 | return $video->getWidth(); 114 | 115 | default: 116 | return parent::__get($name); 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/Proxy/WorkbookProxy.php: -------------------------------------------------------------------------------- 1 | getMyDrive(); 42 | self::$root = self::$defaultDrive->getRoot(); 43 | } 44 | 45 | public function testGetDriveItemById() 46 | { 47 | self::withOnedriveSandbox(self::$root, __METHOD__, function (DriveItemProxy $sandbox) { 48 | $driveItem = $sandbox->upload( 49 | 'Test file', 50 | 'Test content', 51 | [] 52 | ); 53 | 54 | $driveItem = self::$defaultDrive->getDriveItemById($driveItem->id); 55 | $this->assertDriveItemProxy($driveItem); 56 | $this->assertEquals('Test file', $driveItem->name); 57 | }); 58 | } 59 | 60 | public function testGetDriveItemByPath() 61 | { 62 | self::withOnedriveSandbox(self::$root, __METHOD__, function (DriveItemProxy $sandbox) { 63 | $sandbox->upload( 64 | 'Test file', 65 | 'Test content', 66 | [] 67 | ); 68 | 69 | $driveItem = self::$defaultDrive->getDriveItemByPath("/{$sandbox->name}/Test file"); 70 | $this->assertDriveItemProxy($driveItem); 71 | $this->assertEquals('Test file', $driveItem->name); 72 | }); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /test/functional/Router.php: -------------------------------------------------------------------------------- 1 | self::$pollingTimeout) { 29 | throw new \Exception("Timed out while waiting for operation to complete: $uri"); 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/functional/Traits/ClientFactoryTrait.php: -------------------------------------------------------------------------------- 1 | obtainAccessToken($secret, $code); 24 | 25 | return $client; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/functional/Traits/ConfigurationTrait.php: -------------------------------------------------------------------------------- 1 | httpClient === null) { 16 | $this->httpClient = new GuzzleHttpClient(); 17 | } 18 | 19 | $response = $this->httpClient->get($uri); 20 | $json = (string) $response->getBody(); 21 | 22 | return json_decode($json); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/functional/Traits/MicrosoftOauthAuthenticationTrait.php: -------------------------------------------------------------------------------- 1 | get($authorizationRequestUri); 27 | 28 | $nextElementLocator = WebDriverBy::id(self::$nextElementId); 29 | 30 | // Langed on "Sign in" page, submitting username & clicking "Next"... 31 | $usernameElementLocator = WebDriverBy::id(self::$usernameElementId); 32 | self::findElement($webdriver, $usernameElementLocator)->sendKeys($username); 33 | 34 | // Clicking "Next". 35 | self::findElement($webdriver, $nextElementLocator)->click(); 36 | 37 | // Landed on "Enter password" page, submitting password & clicking "Sign 38 | // in"... 39 | $passwordElementLocator = WebDriverBy::id(self::$passwordElementId); 40 | self::findElement($webdriver, $passwordElementLocator)->sendKeys($password); 41 | self::findElement($webdriver, $nextElementLocator)->click(); 42 | 43 | // Landed on "Stay signed in?" page, clicking "Yes"... 44 | self::findElement($webdriver, $nextElementLocator)->click(); 45 | 46 | $expectedUri = preg_quote($redirectUri); 47 | $isMatching = WebDriverExpectedCondition::urlMatches("|^$expectedUri|"); 48 | 49 | $webdriver->wait()->until($isMatching); 50 | } 51 | 52 | private static function findElement(WebDriver $webdriver, WebDriverBy $locator) 53 | { 54 | $isPresent = WebDriverExpectedCondition::presenceOfElementLocated($locator); 55 | $webdriver->wait()->until($isPresent); 56 | 57 | $isVisible = WebDriverExpectedCondition::visibilityOfElementLocated($locator); 58 | $webdriver->wait()->until($isVisible); 59 | 60 | return $webdriver->findElement($locator); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /test/functional/Traits/OauthAuthorizationTrait.php: -------------------------------------------------------------------------------- 1 | getLogInUrl(self::$scopes, $redirectUri, $state); 53 | 54 | $webdriverBaseUri = sprintf( 55 | self::$webdriverBaseUriTemplate, 56 | $webdriverBaseUriScheme, 57 | $webdriverBaseUriHost, 58 | $webdriverBaseUriPort 59 | ); 60 | 61 | $root = dirname(__DIR__); 62 | 63 | $command = [ 64 | 'php', 65 | '--server', 66 | sprintf('%s:%d', $redirectUriAddr, $redirectUriPort), 67 | sprintf('%s/Router.php', $root), 68 | ]; 69 | 70 | return self::withProcess($command, function (Process $process) use ($webdriverBaseUri, $authorizationRequestUri, $redirectUri, $username, $password) { 71 | self::withWebdriver($webdriverBaseUri, function (WebDriver $webdriver) use ($authorizationRequestUri, $redirectUri, $username, $password) { 72 | self::authenticate($webdriver, $authorizationRequestUri, $redirectUri, $username, $password); 73 | }); 74 | 75 | foreach ($process as $type => $buffer) { 76 | if ($type == Process::OUT) { 77 | $lines = explode("\n", $buffer); 78 | $values = self::extractRedirectUriQueryStringValues($lines); 79 | 80 | if ($values !== null) { 81 | return $values; 82 | } 83 | } else { 84 | throw new \Exception("Unsupported process output type: $type"); 85 | } 86 | } 87 | 88 | return null; 89 | }); 90 | } 91 | 92 | private static function extractRedirectUriQueryStringValues(array $lines) 93 | { 94 | foreach ($lines as $line) { 95 | $line = json_decode($line, true); 96 | 97 | if ($line !== null || json_last_error() == JSON_ERROR_NONE) { 98 | return $line; 99 | } 100 | } 101 | 102 | return null; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /test/functional/Traits/OnedriveSandboxTrait.php: -------------------------------------------------------------------------------- 1 | createFolder($name); 18 | 19 | try { 20 | return $callback($sandbox); 21 | } catch (\Exception $exception) { 22 | throw $exception; 23 | } finally { 24 | $sandbox->delete(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/functional/Traits/ProcessTrait.php: -------------------------------------------------------------------------------- 1 | start(); 15 | 16 | try { 17 | return $callback($process); 18 | } catch (\Exception $exception) { 19 | throw $exception; 20 | } finally { 21 | $process->stop(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/functional/Traits/WebdriverTrait.php: -------------------------------------------------------------------------------- 1 | addArguments(self::$arguments); 22 | $caps = DesiredCapabilities::chrome(); 23 | $caps->setCapability(ChromeOptions::CAPABILITY, $opts); 24 | $webdriver = RemoteWebDriver::create($webdriverBaseUri, $caps); 25 | 26 | try { 27 | return $callback($webdriver); 28 | } catch (\Exception $exception) { 29 | throw $exception; 30 | } finally { 31 | $webdriver->quit(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /test/functional/bootstrap.php: -------------------------------------------------------------------------------- 1 | '', 17 | 18 | // A client secret. 19 | // 20 | // It needs to match one of the "Client secrets" values on the 21 | // "Certificate & secrets" page. The full secret values are shown only at 22 | // creation time. 23 | 'SECRET' => '', 24 | 25 | // The account to run the functional test suite from. 26 | // 27 | // DANGER: Any item stored on any drive accessible to this account is 28 | // subject to automated manipulations: it may become damaged or lost. 29 | // DO NOT USE ACCOUNTS WITH ACCESS TO VALUABLE DATA. 30 | 31 | // The username of the account. 32 | 'USERNAME' => '', 33 | 34 | // The password of the account. 35 | 'PASSWORD' => '', 36 | 37 | // The group ID to use when running relevant test cases. 38 | // 39 | // These tests will be skipped if not set. 40 | 'GROUP_ID' => '', 41 | 42 | // The site ID to use when running relevant test cases. 43 | // 44 | // These tests will be skipped if not set. 45 | 'SITE_ID' => '', 46 | 47 | // The email address to send invites to when running relevant test cases. 48 | // 49 | // OneDrive does not allow sending invite to the email address of the 50 | // account signed in; a different email address must be provided. 51 | 'RECIPIENT' => '', 52 | 53 | // The redirect URI. 54 | // 55 | // It needs to match one of the Web Redirect URIs set on the 56 | // "Authentication" page. 57 | 58 | // The IP address of the redirect URI. 59 | 'REDIRECT_URI_ADDR' => '0.0.0.0', 60 | 61 | // The scheme component of the redirect URI. 62 | 'REDIRECT_URI_SCHEME' => 'http', 63 | 64 | // The host component of the redirect URI. 65 | 'REDIRECT_URI_HOST' => 'localhost', 66 | 67 | // The WebDriver base URI. 68 | 69 | // The scheme component of the WebDriver base URI. 70 | 'WEBDRIVER_BASE_URI_SCHEME' => 'http', 71 | 72 | // The host component of the WebDriver base URI. 73 | 'WEBDRIVER_BASE_URI_HOST' => 'localhost', 74 | 75 | // The port component of the WebDriver base URI. Typically 4444. 76 | 'WEBDRIVER_BASE_URI_PORT' => 4444, 77 | ]; 78 | -------------------------------------------------------------------------------- /test/phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | functional 14 | 15 | 16 | unit 17 | 18 | 19 | 20 | 21 | 22 | ../src 23 | 24 | 25 | functional 26 | unit 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /test/unit/Definition/OperationDefinitionTest.php: -------------------------------------------------------------------------------- 1 | createMock(ParameterDefinitionCollectionInterface::class); 16 | 17 | $parameterDefinitionCollection = $this->createMock(ParameterDefinitionCollectionInterface::class); 18 | 19 | $sut = new OperationDefinition( 20 | $bodyParameterDefinitionCollection, 21 | $parameterDefinitionCollection, 22 | $parameterDefinitionCollection 23 | ); 24 | 25 | $actual = $sut->getBodyParameterDefinitions(); 26 | $this->assertSame($bodyParameterDefinitionCollection, $actual); 27 | } 28 | 29 | public function testGetHeaderParameterDefinitionsShouldReturnExpectedValue() 30 | { 31 | $headerParameterDefinitionCollection = $this->createMock(ParameterDefinitionCollectionInterface::class); 32 | 33 | $parameterDefinitionCollection = $this->createMock(ParameterDefinitionCollectionInterface::class); 34 | 35 | $sut = new OperationDefinition( 36 | $parameterDefinitionCollection, 37 | $headerParameterDefinitionCollection, 38 | $parameterDefinitionCollection 39 | ); 40 | 41 | $actual = $sut->getHeaderParameterDefinitions(); 42 | $this->assertSame($headerParameterDefinitionCollection, $actual); 43 | } 44 | 45 | public function testGetQueryStringParameterDefinitionsShouldReturnExpectedValue() 46 | { 47 | $parameterDefinitionCollection = $this->createMock(ParameterDefinitionCollectionInterface::class); 48 | 49 | $queryStringParameterDefinitionCollection = $this->createMock(ParameterDefinitionCollectionInterface::class); 50 | 51 | $sut = new OperationDefinition( 52 | $parameterDefinitionCollection, 53 | $parameterDefinitionCollection, 54 | $queryStringParameterDefinitionCollection 55 | ); 56 | 57 | $actual = $sut->getQueryStringParameterDefinitions(); 58 | $this->assertSame($queryStringParameterDefinitionCollection, $actual); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /test/unit/Definition/Parameter/AbstractParameterDefinitionTest.php: -------------------------------------------------------------------------------- 1 | createMock(InjectorInterface::class); 17 | 18 | $serializer = $this->createMock(SerializerInterface::class); 19 | 20 | $serializer 21 | ->expects($this->once()) 22 | ->method('serialize') 23 | ->with('Value') 24 | ->willReturn('Serialized value'); 25 | 26 | $sut = new TestAbstractParameterDefinition($injector, $serializer); 27 | 28 | $actual = $sut->serializeValue('Value'); 29 | $this->assertSame('Serialized value', $actual); 30 | } 31 | 32 | public function testInjectValueShouldInteractWithItsInjectorAsExpected() 33 | { 34 | $injector = $this->createMock(InjectorInterface::class); 35 | 36 | $injector 37 | ->expects($this->once()) 38 | ->method('inject') 39 | ->with(['key' => 'value'], 'Value') 40 | ->willReturn(['injected_key' => 'Injected value']); 41 | 42 | $serializer = $this->createMock(SerializerInterface::class); 43 | 44 | $sut = new TestAbstractParameterDefinition($injector, $serializer); 45 | 46 | $actual = $sut->injectValue(['key' => 'value'], 'Value'); 47 | $this->assertSame(['injected_key' => 'Injected value'], $actual); 48 | } 49 | } 50 | 51 | class TestAbstractParameterDefinition extends AbstractParameterDefinition 52 | { 53 | } 54 | -------------------------------------------------------------------------------- /test/unit/Definition/ResourceDefinitionTest.php: -------------------------------------------------------------------------------- 1 | createMock(ResourceDefinitionInterface::class); 17 | 18 | $operationDefinitions = [ 19 | 'name1' => $operationDefinition, 20 | 'name2' => $this->createMock(ResourceDefinitionInterface::class), 21 | ]; 22 | 23 | $resourceDefinitions = [ 24 | 'name' => $this->createMock(OperationDefinitionInterface::class), 25 | ]; 26 | 27 | $sut = new ResourceDefinition($operationDefinitions, $resourceDefinitions); 28 | 29 | $actual = $sut->getOperationDefinition('name1'); 30 | $this->assertSame($operationDefinition, $actual); 31 | } 32 | 33 | public function testGetResourceDefinitionShouldReturnExpectedValue() 34 | { 35 | $operationDefinitions = [ 36 | 'name' => $this->createMock(ResourceDefinitionInterface::class), 37 | ]; 38 | 39 | $resourceDefinition = $this->createMock(OperationDefinitionInterface::class); 40 | 41 | $resourceDefinitions = [ 42 | 'name1' => $resourceDefinition, 43 | 'name2' => $this->createMock(OperationDefinitionInterface::class), 44 | ]; 45 | 46 | $sut = new ResourceDefinition($operationDefinitions, $resourceDefinitions); 47 | 48 | $actual = $sut->getResourceDefinition('name1'); 49 | $this->assertSame($resourceDefinition, $actual); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /test/unit/Definition/ServiceDefinitionTest.php: -------------------------------------------------------------------------------- 1 | createMock(ResourceDefinitionInterface::class); 16 | 17 | $resourceDefinitions = [ 18 | 'name1' => $resourceDefinition, 19 | 'name2' => $this->createMock(ResourceDefinitionInterface::class), 20 | ]; 21 | 22 | $sut = new ServiceDefinition($resourceDefinitions); 23 | 24 | $actual = $sut->getResourceDefinition('name1'); 25 | $this->assertSame($resourceDefinition, $actual); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/unit/Parameter/Injector/FlatInjectorTest.php: -------------------------------------------------------------------------------- 1 | inject($values, 'Value'); 19 | $this->assertSame($expected, $actual); 20 | } 21 | 22 | public function provideInjectReturnExpectedValueTestCases() 23 | { 24 | return [ 25 | [ 26 | [], 27 | ['key' => 'Value'], 28 | ], 29 | [ 30 | ['existing_key' => 'Existing value'], 31 | [ 32 | 'existing_key' => 'Existing value', 33 | 'key' => 'Value', 34 | ], 35 | ], 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/unit/Parameter/Injector/HierarchicalInjectorTest.php: -------------------------------------------------------------------------------- 1 | inject($values, 'Value'); 19 | $this->assertSame($expected, $actual); 20 | } 21 | 22 | public function testInjectWithEmptyPathThrowsExpectedException() 23 | { 24 | $this->expectException(\Exception::class); 25 | $this->expectExceptionMessage('A hierarchical injector path cannot be empty'); 26 | 27 | $sut = new HierarchicalInjector([]); 28 | $sut->inject([], 'Irrelevant'); 29 | } 30 | 31 | public function provideInjectReturnExpectedValueTestCases() 32 | { 33 | return [ 34 | [ 35 | ['key'], 36 | [], 37 | ['key' => 'Value'], 38 | ], 39 | [ 40 | ['key'], 41 | ['existing_key' => 'Existing value'], 42 | [ 43 | 'existing_key' => 'Existing value', 44 | 'key' => 'Value', 45 | ], 46 | ], 47 | [ 48 | ['key'], 49 | ['key' => 'Existing value'], 50 | ['key' => 'Value'], 51 | ], 52 | [ 53 | ['path', 'to'], 54 | [], 55 | [ 56 | 'path' => ['to' => 'Value'], 57 | ], 58 | ], 59 | [ 60 | ['path', 'to'], 61 | [ 62 | 'existing_key_1' => 'Existing value #1', 63 | 'path' => ['existing_key_2' => 'Existing value #2'], 64 | ], 65 | [ 66 | 'existing_key_1' => 'Existing value #1', 67 | 'path' => [ 68 | 'existing_key_2' => 'Existing value #2', 69 | 'to' => 'Value', 70 | ], 71 | ], 72 | ], 73 | ]; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /test/unit/Parameter/ParameterBuilderTest.php: -------------------------------------------------------------------------------- 1 | createMock(ParameterDefinitionInterface::class); 16 | 17 | $parameterDefinition1 18 | ->expects($this->atLeastOnce()) 19 | ->method('serializeValue') 20 | ->willReturnCallback(function ($value) { 21 | return "Serialized $value"; 22 | }); 23 | 24 | $parameterDefinition1 25 | ->expects($this->atLeastOnce()) 26 | ->method('injectValue') 27 | ->willReturnCallback(function (array $values, $value) { 28 | return $values + [$value => $value]; 29 | }); 30 | 31 | $parameterDefinition2 = $this->createMock(ParameterDefinitionInterface::class); 32 | 33 | $parameterDefinition2 34 | ->expects($this->atLeastOnce()) 35 | ->method('serializeValue') 36 | ->willReturnCallback(function ($value) { 37 | return "Serialized $value"; 38 | }); 39 | 40 | $parameterDefinition2 41 | ->expects($this->atLeastOnce()) 42 | ->method('injectValue') 43 | ->willReturnCallback(function (array $values, $value) { 44 | return $values + [$value => $value]; 45 | }); 46 | 47 | $sut = new ParameterBuilder(); 48 | 49 | $actual = $sut->build( 50 | [ 51 | '1' => $parameterDefinition1, 52 | '2' => $parameterDefinition2, 53 | '3' => $parameterDefinition2, 54 | ], 55 | [ 56 | '1' => 1, 57 | '2' => 2, 58 | '4' => 4, 59 | ] 60 | ); 61 | 62 | $this->assertSame([ 63 | 'Serialized 1' => 'Serialized 1', 64 | 'Serialized 2' => 'Serialized 2', 65 | ], $actual); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /test/unit/Parameter/ParameterDefinitionCollectionTest.php: -------------------------------------------------------------------------------- 1 | createMock(ParameterBuilderInterface::class); 16 | 17 | $parameterBuilder 18 | ->expects($this->atLeastOnce()) 19 | ->method('build') 20 | ->willReturnCallback(function (array $_, $options) { 21 | return $options; 22 | }); 23 | 24 | $sut = new ParameterDefinitionCollection($parameterBuilder, []); 25 | 26 | $options = ['name' => 'Value']; 27 | $actual = $sut->buildOptions($options); 28 | $this->assertSame($options, $actual); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /test/unit/Proxy/EntityProxyTest.php: -------------------------------------------------------------------------------- 1 | createMock(Graph::class); 17 | 18 | $entity = $this->createMock(Entity::class); 19 | 20 | $entity 21 | ->expects($this->atLeastOnce()) 22 | ->method('getId') 23 | ->willReturn('1234'); 24 | 25 | $sut = new EntityProxy($graph, $entity); 26 | $this->assertIsString($sut->id); 27 | $this->assertSame('1234', $sut->id); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/unit/Proxy/FileProxyTest.php: -------------------------------------------------------------------------------- 1 | createMock(Graph::class); 19 | 20 | $hashes = $this->createMock(Hashes::class); 21 | 22 | $hashes 23 | ->expects($this->atLeastOnce()) 24 | ->method('getCrc32Hash') 25 | ->willReturn('1234'); 26 | 27 | $file = $this->createMock(File::class); 28 | 29 | $file 30 | ->expects($this->atLeastOnce()) 31 | ->method('getHashes') 32 | ->willReturn($hashes); 33 | 34 | $sut = new FileProxy($graph, $file); 35 | $this->assertInstanceOf(HashesProxy::class, $sut->hashes); 36 | $this->assertSame('1234', $sut->hashes->crc32Hash); 37 | } 38 | 39 | public function testMimeTypeShouldReturnExpectedValue() 40 | { 41 | $graph = $this->createMock(Graph::class); 42 | 43 | $file = $this->createMock(File::class); 44 | 45 | $file 46 | ->expects($this->atLeastOnce()) 47 | ->method('getMimeType') 48 | ->willReturn('mime/type'); 49 | 50 | $sut = new FileProxy($graph, $file); 51 | $this->assertIsString($sut->mimeType); 52 | $this->assertSame('mime/type', $sut->mimeType); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/unit/Proxy/FileSystemInfoProxyTest.php: -------------------------------------------------------------------------------- 1 | createMock(Graph::class); 17 | 18 | $dateTime = new \DateTime(); 19 | 20 | $fileSystemInfo = $this->createMock(FileSystemInfo::class); 21 | 22 | $fileSystemInfo 23 | ->expects($this->atLeastOnce()) 24 | ->method('getCreatedDateTime') 25 | ->willReturn($dateTime); 26 | 27 | $sut = new FileSystemInfoProxy($graph, $fileSystemInfo); 28 | $this->assertSame($dateTime, $sut->createdDateTime); 29 | } 30 | 31 | public function testLastAccessedDateTimeShouldReturnExpectedValue() 32 | { 33 | $graph = $this->createMock(Graph::class); 34 | 35 | $dateTime = new \DateTime(); 36 | 37 | $fileSystemInfo = $this->createMock(FileSystemInfo::class); 38 | 39 | $fileSystemInfo 40 | ->expects($this->atLeastOnce()) 41 | ->method('getLastAccessedDateTime') 42 | ->willReturn($dateTime); 43 | 44 | $sut = new FileSystemInfoProxy($graph, $fileSystemInfo); 45 | $this->assertSame($dateTime, $sut->lastAccessedDateTime); 46 | } 47 | 48 | public function testLastModifiedDateTimeShouldReturnExpectedValue() 49 | { 50 | $graph = $this->createMock(Graph::class); 51 | 52 | $dateTime = new \DateTime(); 53 | 54 | $fileSystemInfo = $this->createMock(FileSystemInfo::class); 55 | 56 | $fileSystemInfo 57 | ->expects($this->atLeastOnce()) 58 | ->method('getLastModifiedDateTime') 59 | ->willReturn($dateTime); 60 | 61 | $sut = new FileSystemInfoProxy($graph, $fileSystemInfo); 62 | $this->assertSame($dateTime, $sut->lastModifiedDateTime); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /test/unit/Proxy/FolderProxyTest.php: -------------------------------------------------------------------------------- 1 | createMock(Graph::class); 19 | 20 | $folder = $this->createMock(Folder::class); 21 | 22 | $folder 23 | ->expects($this->atLeastOnce()) 24 | ->method('getChildCount') 25 | ->willReturn(1); 26 | 27 | $sut = new FolderProxy($graph, $folder); 28 | $this->assertIsInt($sut->childCount); 29 | $this->assertSame(1, $sut->childCount); 30 | } 31 | 32 | public function testViewShouldReturnExpectedValue() 33 | { 34 | $graph = $this->createMock(Graph::class); 35 | 36 | $folderView = $this->createMock(FolderView::class); 37 | 38 | $folderView 39 | ->expects($this->atLeastOnce()) 40 | ->method('getSortBy') 41 | ->willReturn('sort_by'); 42 | 43 | $folder = $this->createMock(Folder::class); 44 | 45 | $folder 46 | ->expects($this->atLeastOnce()) 47 | ->method('getView') 48 | ->willReturn($folderView); 49 | 50 | $sut = new FolderProxy($graph, $folder); 51 | $this->assertInstanceOf(FolderViewProxy::class, $sut->view); 52 | $this->assertSame('sort_by', $sut->view->sortBy); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/unit/Proxy/FolderViewProxyTest.php: -------------------------------------------------------------------------------- 1 | createMock(Graph::class); 17 | 18 | $folderView = $this->createMock(FolderView::class); 19 | 20 | $folderView 21 | ->expects($this->atLeastOnce()) 22 | ->method('getSortBy') 23 | ->willReturn('sort_by'); 24 | 25 | $sut = new FolderViewProxy($graph, $folderView); 26 | $this->assertIsString($sut->sortBy); 27 | $this->assertSame('sort_by', $sut->sortBy); 28 | } 29 | 30 | public function testSortOrderShouldReturnExpectedValue() 31 | { 32 | $graph = $this->createMock(Graph::class); 33 | 34 | $folderView = $this->createMock(FolderView::class); 35 | 36 | $folderView 37 | ->expects($this->atLeastOnce()) 38 | ->method('getSortOrder') 39 | ->willReturn('sort_order'); 40 | 41 | $sut = new FolderViewProxy($graph, $folderView); 42 | $this->assertIsString($sut->sortOrder); 43 | $this->assertSame('sort_order', $sut->sortOrder); 44 | } 45 | 46 | public function testViewTypeShouldReturnExpectedValue() 47 | { 48 | $graph = $this->createMock(Graph::class); 49 | 50 | $folderView = $this->createMock(FolderView::class); 51 | 52 | $folderView 53 | ->expects($this->atLeastOnce()) 54 | ->method('getViewType') 55 | ->willReturn('view_type'); 56 | 57 | $sut = new FolderViewProxy($graph, $folderView); 58 | $this->assertIsString($sut->viewType); 59 | $this->assertSame('view_type', $sut->viewType); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /test/unit/Proxy/HashesProxyTest.php: -------------------------------------------------------------------------------- 1 | createMock(Graph::class); 17 | 18 | $hashes = $this->createMock(Hashes::class); 19 | 20 | $hashes 21 | ->expects($this->atLeastOnce()) 22 | ->method('getCrc32Hash') 23 | ->willReturn('1234'); 24 | 25 | $sut = new HashesProxy($graph, $hashes); 26 | $this->assertIsString($sut->crc32Hash); 27 | $this->assertSame('1234', $sut->crc32Hash); 28 | } 29 | 30 | public function testQuickXorHashShouldReturnExpectedValue() 31 | { 32 | $graph = $this->createMock(Graph::class); 33 | 34 | $hashes = $this->createMock(Hashes::class); 35 | 36 | $hashes 37 | ->expects($this->atLeastOnce()) 38 | ->method('getQuickXorHash') 39 | ->willReturn('1234'); 40 | 41 | $sut = new HashesProxy($graph, $hashes); 42 | $this->assertIsString($sut->quickXorHash); 43 | $this->assertSame('1234', $sut->quickXorHash); 44 | } 45 | 46 | public function testSha1HashShouldReturnExpectedValue() 47 | { 48 | $graph = $this->createMock(Graph::class); 49 | 50 | $hashes = $this->createMock(Hashes::class); 51 | 52 | $hashes 53 | ->expects($this->atLeastOnce()) 54 | ->method('getSha1Hash') 55 | ->willReturn('1234'); 56 | 57 | $sut = new HashesProxy($graph, $hashes); 58 | $this->assertIsString($sut->sha1Hash); 59 | $this->assertSame('1234', $sut->sha1Hash); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /test/unit/Proxy/IdentityProxyTest.php: -------------------------------------------------------------------------------- 1 | createMock(Graph::class); 17 | 18 | $identity = $this->createMock(Identity::class); 19 | 20 | $identity 21 | ->expects($this->atLeastOnce()) 22 | ->method('getDisplayName') 23 | ->willReturn('Display Name'); 24 | 25 | $sut = new IdentityProxy($graph, $identity); 26 | $this->assertIsString($sut->displayName); 27 | $this->assertSame('Display Name', $sut->displayName); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/unit/Proxy/IdentitySetProxyTest.php: -------------------------------------------------------------------------------- 1 | createMock(Graph::class); 19 | 20 | $identity = $this->createMock(Identity::class); 21 | 22 | $identity 23 | ->expects($this->atLeastOnce()) 24 | ->method('getDisplayName') 25 | ->willReturn('Display Name'); 26 | 27 | $identitySet = $this->createMock(IdentitySet::class); 28 | 29 | $identitySet 30 | ->expects($this->atLeastOnce()) 31 | ->method('getApplication') 32 | ->willReturn($identity); 33 | 34 | $sut = new IdentitySetProxy($graph, $identitySet); 35 | $this->assertInstanceOf(IdentityProxy::class, $sut->application); 36 | $this->assertSame('Display Name', $sut->application->displayName); 37 | } 38 | 39 | public function testDeviceShouldReturnExpectedValue() 40 | { 41 | $graph = $this->createMock(Graph::class); 42 | 43 | $identity = $this->createMock(Identity::class); 44 | 45 | $identity 46 | ->expects($this->atLeastOnce()) 47 | ->method('getDisplayName') 48 | ->willReturn('Display Name'); 49 | 50 | $identitySet = $this->createMock(IdentitySet::class); 51 | 52 | $identitySet 53 | ->expects($this->atLeastOnce()) 54 | ->method('getDevice') 55 | ->willReturn($identity); 56 | 57 | $sut = new IdentitySetProxy($graph, $identitySet); 58 | $this->assertInstanceOf(IdentityProxy::class, $sut->device); 59 | $this->assertSame('Display Name', $sut->device->displayName); 60 | } 61 | 62 | public function testUserShouldReturnExpectedValue() 63 | { 64 | $graph = $this->createMock(Graph::class); 65 | 66 | $identity = $this->createMock(Identity::class); 67 | 68 | $identity 69 | ->expects($this->atLeastOnce()) 70 | ->method('getDisplayName') 71 | ->willReturn('Display Name'); 72 | 73 | $identitySet = $this->createMock(IdentitySet::class); 74 | 75 | $identitySet 76 | ->expects($this->atLeastOnce()) 77 | ->method('getUser') 78 | ->willReturn($identity); 79 | 80 | $sut = new IdentitySetProxy($graph, $identitySet); 81 | $this->assertInstanceOf(IdentityProxy::class, $sut->user); 82 | $this->assertSame('Display Name', $sut->user->displayName); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /test/unit/Proxy/ImageProxyTest.php: -------------------------------------------------------------------------------- 1 | createMock(Graph::class); 17 | 18 | $image = $this->createMock(Image::class); 19 | 20 | $image 21 | ->expects($this->atLeastOnce()) 22 | ->method('getHeight') 23 | ->willReturn(123); 24 | 25 | $sut = new ImageProxy($graph, $image); 26 | $this->assertSame(123, $sut->height); 27 | } 28 | 29 | public function testWidthShouldReturnExpectedValue() 30 | { 31 | $graph = $this->createMock(Graph::class); 32 | 33 | $image = $this->createMock(Image::class); 34 | 35 | $image 36 | ->expects($this->atLeastOnce()) 37 | ->method('getWidth') 38 | ->willReturn(123); 39 | 40 | $sut = new ImageProxy($graph, $image); 41 | $this->assertSame(123, $sut->width); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /test/unit/Proxy/ItemReferenceProxyTest.php: -------------------------------------------------------------------------------- 1 | createMock(Graph::class); 18 | 19 | $itemReference = $this->createMock(ItemReference::class); 20 | 21 | $itemReference 22 | ->expects($this->atLeastOnce()) 23 | ->method('getId') 24 | ->willReturn('1234'); 25 | 26 | $sut = new ItemReferenceProxy($graph, $itemReference); 27 | $this->assertIsString($sut->id); 28 | $this->assertSame('1234', $sut->id); 29 | } 30 | 31 | public function testDriveIdShouldReturnExpectedValue() 32 | { 33 | $graph = $this->createMock(Graph::class); 34 | 35 | $itemReference = $this->createMock(ItemReference::class); 36 | 37 | $itemReference 38 | ->expects($this->atLeastOnce()) 39 | ->method('getDriveId') 40 | ->willReturn('1234'); 41 | 42 | $sut = new ItemReferenceProxy($graph, $itemReference); 43 | $this->assertIsString($sut->driveId); 44 | $this->assertSame('1234', $sut->driveId); 45 | } 46 | 47 | public function testDriveTypeShouldReturnExpectedValue() 48 | { 49 | $graph = $this->createMock(Graph::class); 50 | 51 | $itemReference = $this->createMock(ItemReference::class); 52 | 53 | $itemReference 54 | ->expects($this->atLeastOnce()) 55 | ->method('getDriveType') 56 | ->willReturn(DriveType::PERSONAL); 57 | 58 | $sut = new ItemReferenceProxy($graph, $itemReference); 59 | $this->assertIsString($sut->driveType); 60 | $this->assertSame(DriveType::PERSONAL, $sut->driveType); 61 | } 62 | 63 | public function testPathShouldReturnExpectedValue() 64 | { 65 | $graph = $this->createMock(Graph::class); 66 | 67 | $itemReference = $this->createMock(ItemReference::class); 68 | 69 | $itemReference 70 | ->expects($this->atLeastOnce()) 71 | ->method('getPath') 72 | ->willReturn('/path'); 73 | 74 | $sut = new ItemReferenceProxy($graph, $itemReference); 75 | $this->assertIsString($sut->path); 76 | $this->assertSame('/path', $sut->path); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /test/unit/Proxy/PackageProxyTest.php: -------------------------------------------------------------------------------- 1 | createMock(Graph::class); 18 | 19 | $package = $this->createMock(Package::class); 20 | 21 | $package 22 | ->expects($this->atLeastOnce()) 23 | ->method('getType') 24 | ->willReturn(PackageType::ONENOTE); 25 | 26 | $sut = new PackageProxy($graph, $package); 27 | $this->assertIsString($sut->type); 28 | $this->assertSame(PackageType::ONENOTE, $sut->type); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /test/unit/Proxy/PhotoProxyTest.php: -------------------------------------------------------------------------------- 1 | createMock(Graph::class); 17 | 18 | $photo = $this->createMock(Photo::class); 19 | 20 | $photo 21 | ->expects($this->atLeastOnce()) 22 | ->method('getCameraMake') 23 | ->willReturn('Test Camera Make'); 24 | 25 | $sut = new PhotoProxy($graph, $photo); 26 | $this->assertSame('Test Camera Make', $sut->cameraMake); 27 | } 28 | 29 | public function testCameraModelShouldReturnExpectedValue() 30 | { 31 | $graph = $this->createMock(Graph::class); 32 | 33 | $photo = $this->createMock(Photo::class); 34 | 35 | $photo 36 | ->expects($this->atLeastOnce()) 37 | ->method('getCameraModel') 38 | ->willReturn('Test Camera Model'); 39 | 40 | $sut = new PhotoProxy($graph, $photo); 41 | $this->assertSame('Test Camera Model', $sut->cameraModel); 42 | } 43 | 44 | public function testExposureDenominatorShouldReturnExpectedValue() 45 | { 46 | $graph = $this->createMock(Graph::class); 47 | 48 | $photo = $this->createMock(Photo::class); 49 | 50 | $photo 51 | ->expects($this->atLeastOnce()) 52 | ->method('getExposureDenominator') 53 | ->willReturn(1.23); 54 | 55 | $sut = new PhotoProxy($graph, $photo); 56 | $this->assertSame(1.23, $sut->exposureDenominator); 57 | } 58 | 59 | public function testExposureNumeratorShouldReturnExpectedValue() 60 | { 61 | $graph = $this->createMock(Graph::class); 62 | 63 | $photo = $this->createMock(Photo::class); 64 | 65 | $photo 66 | ->expects($this->atLeastOnce()) 67 | ->method('getExposureNumerator') 68 | ->willReturn(1.23); 69 | 70 | $sut = new PhotoProxy($graph, $photo); 71 | $this->assertSame(1.23, $sut->exposureNumerator); 72 | } 73 | 74 | public function testFNumberShouldReturnExpectedValue() 75 | { 76 | $graph = $this->createMock(Graph::class); 77 | 78 | $photo = $this->createMock(Photo::class); 79 | 80 | $photo 81 | ->expects($this->atLeastOnce()) 82 | ->method('getFNumber') 83 | ->willReturn(1.23); 84 | 85 | $sut = new PhotoProxy($graph, $photo); 86 | $this->assertSame(1.23, $sut->fNumber); 87 | } 88 | 89 | public function testFocalLengthShouldReturnExpectedValue() 90 | { 91 | $graph = $this->createMock(Graph::class); 92 | 93 | $photo = $this->createMock(Photo::class); 94 | 95 | $photo 96 | ->expects($this->atLeastOnce()) 97 | ->method('getFocalLength') 98 | ->willReturn(1.23); 99 | 100 | $sut = new PhotoProxy($graph, $photo); 101 | $this->assertSame(1.23, $sut->focalLength); 102 | } 103 | 104 | public function testIsoShouldReturnExpectedValue() 105 | { 106 | $graph = $this->createMock(Graph::class); 107 | 108 | $photo = $this->createMock(Photo::class); 109 | 110 | $photo 111 | ->expects($this->atLeastOnce()) 112 | ->method('getIso') 113 | ->willReturn(123); 114 | 115 | $sut = new PhotoProxy($graph, $photo); 116 | $this->assertSame(123, $sut->iso); 117 | } 118 | 119 | public function testTakenDateTimeShouldReturnExpectedValue() 120 | { 121 | $graph = $this->createMock(Graph::class); 122 | 123 | $dateTime = new \DateTime(); 124 | 125 | $photo = $this->createMock(Photo::class); 126 | 127 | $photo 128 | ->expects($this->atLeastOnce()) 129 | ->method('getTakenDateTime') 130 | ->willReturn($dateTime); 131 | 132 | $sut = new PhotoProxy($graph, $photo); 133 | $this->assertSame($dateTime, $sut->takenDateTime); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /test/unit/Proxy/QuotaProxyTest.php: -------------------------------------------------------------------------------- 1 | createMock(Graph::class); 17 | 18 | $quota = $this->createMock(Quota::class); 19 | 20 | $quota 21 | ->expects($this->atLeastOnce()) 22 | ->method('getDeleted') 23 | ->willReturn(1234); 24 | 25 | $sut = new QuotaProxy($graph, $quota); 26 | $this->assertIsInt($sut->deleted); 27 | $this->assertSame(1234, $sut->deleted); 28 | } 29 | 30 | public function testRemainingShouldReturnExpectedValue() 31 | { 32 | $graph = $this->createMock(Graph::class); 33 | 34 | $quota = $this->createMock(Quota::class); 35 | 36 | $quota 37 | ->expects($this->atLeastOnce()) 38 | ->method('getRemaining') 39 | ->willReturn(1234); 40 | 41 | $sut = new QuotaProxy($graph, $quota); 42 | $this->assertIsInt($sut->remaining); 43 | $this->assertSame(1234, $sut->remaining); 44 | } 45 | 46 | public function testStateShouldReturnExpectedValue() 47 | { 48 | $graph = $this->createMock(Graph::class); 49 | 50 | $quota = $this->createMock(Quota::class); 51 | 52 | $quota 53 | ->expects($this->atLeastOnce()) 54 | ->method('getState') 55 | ->willReturn(1234); 56 | 57 | $sut = new QuotaProxy($graph, $quota); 58 | $this->assertIsInt($sut->state); 59 | $this->assertSame(1234, $sut->state); 60 | } 61 | 62 | public function testTotalShouldReturnExpectedValue() 63 | { 64 | $graph = $this->createMock(Graph::class); 65 | 66 | $quota = $this->createMock(Quota::class); 67 | 68 | $quota 69 | ->expects($this->atLeastOnce()) 70 | ->method('getTotal') 71 | ->willReturn(1234); 72 | 73 | $sut = new QuotaProxy($graph, $quota); 74 | $this->assertIsInt($sut->total); 75 | $this->assertSame(1234, $sut->total); 76 | } 77 | 78 | public function testUsedShouldReturnExpectedValue() 79 | { 80 | $graph = $this->createMock(Graph::class); 81 | 82 | $quota = $this->createMock(Quota::class); 83 | 84 | $quota 85 | ->expects($this->atLeastOnce()) 86 | ->method('getUsed') 87 | ->willReturn(1234); 88 | 89 | $sut = new QuotaProxy($graph, $quota); 90 | $this->assertIsInt($sut->used); 91 | $this->assertSame(1234, $sut->used); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /test/unit/Proxy/SharedProxyTest.php: -------------------------------------------------------------------------------- 1 | createMock(Graph::class); 20 | 21 | $identity = $this->createMock(Identity::class); 22 | 23 | $identity 24 | ->expects($this->atLeastOnce()) 25 | ->method('getDisplayName') 26 | ->willReturn('Display Name'); 27 | 28 | $identitySet = $this->createMock(IdentitySet::class); 29 | 30 | $identitySet 31 | ->expects($this->atLeastOnce()) 32 | ->method('getApplication') 33 | ->willReturn($identity); 34 | 35 | $shared = $this->createMock(Shared::class); 36 | 37 | $shared 38 | ->expects($this->atLeastOnce()) 39 | ->method('getOwner') 40 | ->willReturn($identitySet); 41 | 42 | $sut = new SharedProxy($graph, $shared); 43 | $this->assertIsString($sut->owner->application->displayName); 44 | $this->assertSame('Display Name', $sut->owner->application->displayName); 45 | } 46 | 47 | public function testScopeShouldReturnExpectedValue() 48 | { 49 | $graph = $this->createMock(Graph::class); 50 | 51 | $shared = $this->createMock(Shared::class); 52 | 53 | $shared 54 | ->expects($this->atLeastOnce()) 55 | ->method('getScope') 56 | ->willReturn(SharedScope::ANONYMOUS); 57 | 58 | $sut = new SharedProxy($graph, $shared); 59 | $this->assertIsString($sut->scope); 60 | $this->assertSame(SharedScope::ANONYMOUS, $sut->scope); 61 | } 62 | 63 | public function testSharedByShouldReturnExpectedValue() 64 | { 65 | $graph = $this->createMock(Graph::class); 66 | 67 | $identity = $this->createMock(Identity::class); 68 | 69 | $identity 70 | ->expects($this->atLeastOnce()) 71 | ->method('getDisplayName') 72 | ->willReturn('Display Name'); 73 | 74 | $identitySet = $this->createMock(IdentitySet::class); 75 | 76 | $identitySet 77 | ->expects($this->atLeastOnce()) 78 | ->method('getApplication') 79 | ->willReturn($identity); 80 | 81 | $shared = $this->createMock(Shared::class); 82 | 83 | $shared 84 | ->expects($this->atLeastOnce()) 85 | ->method('getSharedBy') 86 | ->willReturn($identitySet); 87 | 88 | $sut = new SharedProxy($graph, $shared); 89 | $this->assertIsString($sut->sharedBy->application->displayName); 90 | $this->assertSame('Display Name', $sut->sharedBy->application->displayName); 91 | } 92 | 93 | public function testSharedDateTimeShouldReturnExpectedValue() 94 | { 95 | $graph = $this->createMock(Graph::class); 96 | 97 | $dateTime = new \DateTime(); 98 | 99 | $shared = $this->createMock(Shared::class); 100 | 101 | $shared 102 | ->expects($this->atLeastOnce()) 103 | ->method('getSharedDateTime') 104 | ->willReturn($dateTime); 105 | 106 | $sut = new SharedProxy($graph, $shared); 107 | $this->assertSame($dateTime, $sut->sharedDateTime); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /test/unit/Proxy/SharepointIdsProxyTest.php: -------------------------------------------------------------------------------- 1 | createMock(Graph::class); 17 | 18 | $sharepointIds = $this->createMock(SharepointIds::class); 19 | 20 | $sharepointIds 21 | ->expects($this->atLeastOnce()) 22 | ->method('getListId') 23 | ->willReturn('1234'); 24 | 25 | $sut = new SharepointIdsProxy($graph, $sharepointIds); 26 | $this->assertIsString($sut->listId); 27 | $this->assertSame('1234', $sut->listId); 28 | } 29 | 30 | public function testListItemIdShouldReturnExpectedValue() 31 | { 32 | $graph = $this->createMock(Graph::class); 33 | 34 | $sharepointIds = $this->createMock(SharepointIds::class); 35 | 36 | $sharepointIds 37 | ->expects($this->atLeastOnce()) 38 | ->method('getListItemId') 39 | ->willReturn('1234'); 40 | 41 | $sut = new SharepointIdsProxy($graph, $sharepointIds); 42 | $this->assertIsString($sut->listItemId); 43 | $this->assertSame('1234', $sut->listItemId); 44 | } 45 | 46 | public function testListItemUniqueIdShouldReturnExpectedValue() 47 | { 48 | $graph = $this->createMock(Graph::class); 49 | 50 | $sharepointIds = $this->createMock(SharepointIds::class); 51 | 52 | $sharepointIds 53 | ->expects($this->atLeastOnce()) 54 | ->method('getListItemUniqueId') 55 | ->willReturn('1234'); 56 | 57 | $sut = new SharepointIdsProxy($graph, $sharepointIds); 58 | $this->assertIsString($sut->listItemUniqueId); 59 | $this->assertSame('1234', $sut->listItemUniqueId); 60 | } 61 | 62 | public function testSiteIdShouldReturnExpectedValue() 63 | { 64 | $graph = $this->createMock(Graph::class); 65 | 66 | $sharepointIds = $this->createMock(SharepointIds::class); 67 | 68 | $sharepointIds 69 | ->expects($this->atLeastOnce()) 70 | ->method('getSiteId') 71 | ->willReturn('1234'); 72 | 73 | $sut = new SharepointIdsProxy($graph, $sharepointIds); 74 | $this->assertIsString($sut->siteId); 75 | $this->assertSame('1234', $sut->siteId); 76 | } 77 | 78 | public function testSiteUrlShouldReturnExpectedValue() 79 | { 80 | $graph = $this->createMock(Graph::class); 81 | 82 | $sharepointIds = $this->createMock(SharepointIds::class); 83 | 84 | $sharepointIds 85 | ->expects($this->atLeastOnce()) 86 | ->method('getSiteUrl') 87 | ->willReturn('http://si.te/url'); 88 | 89 | $sut = new SharepointIdsProxy($graph, $sharepointIds); 90 | $this->assertIsString($sut->siteUrl); 91 | $this->assertSame('http://si.te/url', $sut->siteUrl); 92 | } 93 | 94 | public function testWebIdShouldReturnExpectedValue() 95 | { 96 | $graph = $this->createMock(Graph::class); 97 | 98 | $sharepointIds = $this->createMock(SharepointIds::class); 99 | 100 | $sharepointIds 101 | ->expects($this->atLeastOnce()) 102 | ->method('getWebId') 103 | ->willReturn('1234'); 104 | 105 | $sut = new SharepointIdsProxy($graph, $sharepointIds); 106 | $this->assertIsString($sut->webId); 107 | $this->assertSame('1234', $sut->webId); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /test/unit/Proxy/SharingLinkProxyTest.php: -------------------------------------------------------------------------------- 1 | createMock(Graph::class); 21 | 22 | $identity = $this->createMock(Identity::class); 23 | 24 | $identity 25 | ->expects($this->atLeastOnce()) 26 | ->method('getDisplayName') 27 | ->willReturn('Display Name'); 28 | 29 | $sharingLink = $this->createMock(SharingLink::class); 30 | 31 | $sharingLink 32 | ->expects($this->atLeastOnce()) 33 | ->method('getApplication') 34 | ->willReturn($identity); 35 | 36 | $sut = new SharingLinkProxy($graph, $sharingLink); 37 | $this->assertInstanceOf(IdentityProxy::class, $sut->application); 38 | $this->assertSame('Display Name', $sut->application->displayName); 39 | } 40 | 41 | public function testScopeShouldReturnExpectedValue() 42 | { 43 | $graph = $this->createMock(Graph::class); 44 | 45 | $sharingLink = $this->createMock(SharingLink::class); 46 | 47 | $sharingLink 48 | ->expects($this->atLeastOnce()) 49 | ->method('getScope') 50 | ->willReturn(SharingLinkScope::ANONYMOUS); 51 | 52 | $sut = new SharingLinkProxy($graph, $sharingLink); 53 | $this->assertIsString($sut->scope); 54 | $this->assertSame(SharingLinkScope::ANONYMOUS, $sut->scope); 55 | } 56 | 57 | public function testTypeShouldReturnExpectedValue() 58 | { 59 | $graph = $this->createMock(Graph::class); 60 | 61 | $sharingLink = $this->createMock(SharingLink::class); 62 | 63 | $sharingLink 64 | ->expects($this->atLeastOnce()) 65 | ->method('getType') 66 | ->willReturn(SharingLinkType::VIEW); 67 | 68 | $sut = new SharingLinkProxy($graph, $sharingLink); 69 | $this->assertIsString($sut->type); 70 | $this->assertSame(SharingLinkType::VIEW, $sut->type); 71 | } 72 | 73 | public function testWebUrlShouldReturnExpectedValue() 74 | { 75 | $graph = $this->createMock(Graph::class); 76 | 77 | $sharingLink = $this->createMock(SharingLink::class); 78 | 79 | $sharingLink 80 | ->expects($this->atLeastOnce()) 81 | ->method('getWebUrl') 82 | ->willReturn('http://ho.st/web-url'); 83 | 84 | $sut = new SharingLinkProxy($graph, $sharingLink); 85 | $this->assertIsString($sut->webUrl); 86 | $this->assertSame('http://ho.st/web-url', $sut->webUrl); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /test/unit/Proxy/SpecialFolderProxyTest.php: -------------------------------------------------------------------------------- 1 | createMock(Graph::class); 17 | 18 | $specialFolder = $this->createMock(SpecialFolder::class); 19 | 20 | $specialFolder 21 | ->expects($this->atLeastOnce()) 22 | ->method('getName') 23 | ->willReturn('Name'); 24 | 25 | $sut = new SpecialFolderProxy($graph, $specialFolder); 26 | $this->assertIsString($sut->name); 27 | $this->assertSame('Name', $sut->name); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/unit/Proxy/VideoProxyTest.php: -------------------------------------------------------------------------------- 1 | createMock(Graph::class); 17 | 18 | $video = $this->createMock(Video::class); 19 | 20 | $video 21 | ->expects($this->atLeastOnce()) 22 | ->method('getAudioBitsPerSample') 23 | ->willReturn(123); 24 | 25 | $sut = new VideoProxy($graph, $video); 26 | $this->assertSame(123, $sut->audioBitsPerSample); 27 | } 28 | 29 | public function testAudioChannelsShouldReturnExpectedValue() 30 | { 31 | $graph = $this->createMock(Graph::class); 32 | 33 | $video = $this->createMock(Video::class); 34 | 35 | $video 36 | ->expects($this->atLeastOnce()) 37 | ->method('getAudioChannels') 38 | ->willReturn(123); 39 | 40 | $sut = new VideoProxy($graph, $video); 41 | $this->assertSame(123, $sut->audioChannels); 42 | } 43 | 44 | public function testAudioFormatShouldReturnExpectedValue() 45 | { 46 | $graph = $this->createMock(Graph::class); 47 | 48 | $video = $this->createMock(Video::class); 49 | 50 | $video 51 | ->expects($this->atLeastOnce()) 52 | ->method('getAudioFormat') 53 | ->willReturn('TestAudioFormat'); 54 | 55 | $sut = new VideoProxy($graph, $video); 56 | $this->assertSame('TestAudioFormat', $sut->audioFormat); 57 | } 58 | 59 | public function testAudioSamplesPerSecondShouldReturnExpectedValue() 60 | { 61 | $graph = $this->createMock(Graph::class); 62 | 63 | $video = $this->createMock(Video::class); 64 | 65 | $video 66 | ->expects($this->atLeastOnce()) 67 | ->method('getAudioSamplesPerSecond') 68 | ->willReturn(123); 69 | 70 | $sut = new VideoProxy($graph, $video); 71 | $this->assertSame(123, $sut->audioSamplesPerSecond); 72 | } 73 | 74 | public function testBitrateShouldReturnExpectedValue() 75 | { 76 | $graph = $this->createMock(Graph::class); 77 | 78 | $video = $this->createMock(Video::class); 79 | 80 | $video 81 | ->expects($this->atLeastOnce()) 82 | ->method('getBitrate') 83 | ->willReturn(123); 84 | 85 | $sut = new VideoProxy($graph, $video); 86 | $this->assertSame(123, $sut->bitrate); 87 | } 88 | 89 | public function testDurationShouldReturnExpectedValue() 90 | { 91 | $graph = $this->createMock(Graph::class); 92 | 93 | $video = $this->createMock(Video::class); 94 | 95 | $video 96 | ->expects($this->atLeastOnce()) 97 | ->method('getDuration') 98 | ->willReturn(123); 99 | 100 | $sut = new VideoProxy($graph, $video); 101 | $this->assertSame(123, $sut->duration); 102 | } 103 | 104 | public function testFourCCFormatShouldReturnExpectedValue() 105 | { 106 | $graph = $this->createMock(Graph::class); 107 | 108 | $video = $this->createMock(Video::class); 109 | 110 | $video 111 | ->expects($this->atLeastOnce()) 112 | ->method('getFourCC') 113 | ->willReturn('TestFourCC'); 114 | 115 | $sut = new VideoProxy($graph, $video); 116 | $this->assertSame('TestFourCC', $sut->fourCc); 117 | } 118 | 119 | public function testFrameRateShouldReturnExpectedValue() 120 | { 121 | $graph = $this->createMock(Graph::class); 122 | 123 | $video = $this->createMock(Video::class); 124 | 125 | $video 126 | ->expects($this->atLeastOnce()) 127 | ->method('getFrameRate') 128 | ->willReturn(1.23); 129 | 130 | $sut = new VideoProxy($graph, $video); 131 | $this->assertSame(1.23, $sut->frameRate); 132 | } 133 | 134 | public function testHeightShouldReturnExpectedValue() 135 | { 136 | $graph = $this->createMock(Graph::class); 137 | 138 | $video = $this->createMock(Video::class); 139 | 140 | $video 141 | ->expects($this->atLeastOnce()) 142 | ->method('getHeight') 143 | ->willReturn(123); 144 | 145 | $sut = new VideoProxy($graph, $video); 146 | $this->assertSame(123, $sut->height); 147 | } 148 | 149 | public function testWidthRateShouldReturnExpectedValue() 150 | { 151 | $graph = $this->createMock(Graph::class); 152 | 153 | $video = $this->createMock(Video::class); 154 | 155 | $video 156 | ->expects($this->atLeastOnce()) 157 | ->method('getWidth') 158 | ->willReturn(123); 159 | 160 | $sut = new VideoProxy($graph, $video); 161 | $this->assertSame(123, $sut->width); 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /test/unit/Serializer/OrderBySerializerTest.php: -------------------------------------------------------------------------------- 1 | serialize([ 17 | ['a', 'asc'], 18 | ['b', 'desc'], 19 | ]); 20 | 21 | $this->assertSame('a asc, b desc', $actual); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /test/unit/Serializer/ScalarSerializerTest.php: -------------------------------------------------------------------------------- 1 | serialize($value); 20 | $this->assertSame($expected, $actual); 21 | } 22 | 23 | public function valueProvider() 24 | { 25 | return [ 26 | ['Test', 'Test'], 27 | [1234, '1234'], 28 | [false, 'false'], 29 | [true, 'true'], 30 | ]; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/unit/bootstrap.php: -------------------------------------------------------------------------------- 1 |