diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..17d5dc6 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +/.gitattributes export-ignore +/.gitignore export-ignore +/.github export-ignore diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..0195a70 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,31 @@ +name: Run phpunit tests + +permissions: + contents: read + +on: [push] + +jobs: + test-php: + name: Test on php ${{ matrix.php-version }} and ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + php-version: ["8.1", "8.2", "8.3"] + os: [ubuntu-latest] + steps: + - uses: actions/checkout@v4 + - name: Use php ${{ matrix.php-version }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + - name: Cache module + uses: actions/cache@v3 + with: + path: ~/.composer/cache/ + key: composer-cache + - name: Install dependencies + run: composer install --no-interaction + - name: Run php tests + run: ./vendor/bin/phpunit \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7a1e76a..a62d70a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ vendor/* composer.lock .idea +.vscode .phpunit.cache/* -.phpunit.*.cache \ No newline at end of file +.phpunit.*.cache diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..483d564 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2015-2018 xu ding + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/composer.json b/composer.json index b67d234..a27f293 100644 --- a/composer.json +++ b/composer.json @@ -25,5 +25,10 @@ "psr-4": { "Dilab\\Test\\": "test/src/" } + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } } } diff --git a/test/src/ResumableTest.php b/test/src/ResumableTest.php index 4afe706..68673ee 100644 --- a/test/src/ResumableTest.php +++ b/test/src/ResumableTest.php @@ -115,7 +115,7 @@ public function testHandleTestChunk() $this->response->expects($this->once()) ->method('header') - ->with($this->equalTo(200)); + ->with($this->equalTo(201)); $this->resumbable = new Resumable($this->request,$this->response); $this->resumbable->tempFolder = 'test/tmp'; @@ -184,22 +184,25 @@ public function testResumableParamsGetRequest() public static function isFileUploadCompleteProvider() { - return array( - array('mock.png', 'files', 20, 60, true), - array('mock.png','files', 25, 60, true), - array('mock.png','files', 10, 60, false), - ); + return [ + ['mock.png', 'files', 1, true],// test/files/0001-0003 exist + ['mock.png', 'files', 2, true],// test/files/0001-0003 exist + ['mock.png', 'files', 3, true],// test/files/0001-0003 exist + ['mock.png', 'files', 4, false],// no 0004 chunk + ['mock.png', 'files', 5, false],// no 0004-0005 chunks + ['mock.png', 'files', 15, false],// no 0004-00015 chunks + ]; } /** * * @dataProvider isFileUploadCompleteProvider */ - public function testIsFileUploadComplete($filename,$identifier, $chunkSize, $totalSize, $expected) + public function testIsFileUploadComplete($filename,$identifier, $totalChunks, $expected) { $this->resumbable = new Resumable($this->request,$this->response); $this->resumbable->tempFolder ='test'; - $this->assertEquals($expected, $this->resumbable->isFileUploadComplete($filename, $identifier, $chunkSize, $totalSize)); + $this->assertEquals($expected, $this->resumbable->isFileUploadComplete($filename, $identifier, $totalChunks)); } public function testIsChunkUploaded()