diff --git a/.gitattributes b/.gitattributes index 9960195..3eb38bd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,5 @@ +/.github export-ignore /tests export-ignore /.gitattributes export-ignore /.gitignore export-ignore -/.travis.yml export-ignore /phpunit.xml export-ignore diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..4b46627 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,38 @@ +name: tests + +on: + push: + pull_request: + +jobs: + test: + + runs-on: ubuntu-latest + timeout-minutes: 15 + strategy: + fail-fast: false + matrix: + php: [7.4, 8.0] + composer-flag: [prefer-lowest, prefer-stable] + + name: php v${{ matrix.php }} - ${{ matrix.composer-flag }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pdo, bcmath, gmp + tools: composer:v2 + + - name: Install dependencies + run: composer update --${{ matrix.composer-flag }} --no-interaction --no-progress + + - name: Execute tests + run: | + mkdir -p build/logs + composer test -- --coverage-clover build/logs/clover.xml + [ -f build/logs/clover.xml ] && ./vendor/bin/php-coveralls -v || echo 'clover.xml not found.' diff --git a/.gitignore b/.gitignore index 8b7ef35..c626c17 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /vendor +/build/ composer.lock +/.phpunit.result.cache diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b82059d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -language: php - -php: - - 7.0 - - 7.1 - - 7.2 - - 7.3 - -sudo: false - -before_script: - - travis_retry composer self-update - - travis_retry composer install --no-interaction - -script: - - mkdir -p build/logs - - ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml - -after_success: - - php vendor/bin/coveralls -v diff --git a/LICENSE.md b/LICENSE.md index 948b1b1..2bca0d4 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Jens Segers +Copyright (c) 2021 Jens Segers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 7529621..b7f4357 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ -Optimus id transformation -========================= - -[![Latest Stable Version](http://img.shields.io/github/release/jenssegers/optimus.svg)](https://packagist.org/packages/jenssegers/optimus) [![Build Status](http://img.shields.io/travis/jenssegers/optimus.svg)](https://travis-ci.org/jenssegers/optimus) [![Coverage Status](http://img.shields.io/coveralls/jenssegers/optimus.svg)](https://coveralls.io/r/jenssegers/optimus?branch=master) +# Optimus id transformation +[![Packagist](https://badgen.net/packagist/v/jenssegers/optimus)](https://packagist.org/packages/jenssegers/optimus) +[![Downloads](https://badgen.net/packagist/dt/jenssegers/optimus)](https://packagist.org/packages/jenssegers/optimus/stats) +[![Build](https://github.com/jenssegers/optimus/workflows/tests/badge.svg)](https://github.com/jenssegers/optimus/actions) +[![Coverage](http://img.shields.io/coveralls/jenssegers/optimus.svg)](https://coveralls.io/r/jenssegers/optimus?branch=master) With this library, you can transform your internal id's to obfuscated integers based on Knuth's integer hash. It is similar to Hashids, but will generate integers instead of random strings. It is also super fast. @@ -10,25 +11,26 @@ With this library, you can transform your internal id's to obfuscated integers b

-Installation ------------- +## Installation Install using composer: -``` +```bash composer require jenssegers/optimus ``` -If you will be running your code on a 32 bit system or will be working with large prime numbers it is suggested that you install the [GMP extension](http://php.net/manual/en/book.gmp.php). For debian/ubuntu you can install the extension with one of these commands: +If you will be running your code on a 32 bit system or will be working with large prime numbers it is suggested that you install the [GMP extension](http://php.net/manual/en/book.gmp.php). +For debian/ubuntu you can install the extension with one of these commands: -``` +```bash apt-get install php7.0-gmp apt-get install php7.1-gmp apt-get install php7.2-gmp +apt-get install php7.3-gmp +apt-get install php7.4-gmp ``` -Usage ------ +## Usage To get started you will need 3 things; @@ -38,7 +40,7 @@ To get started you will need 3 things; Luckily for you, I have included a console command that can do all of this for you. To get started, just run the following command: -``` +```bash > php vendor/bin/optimus spark Prime: 2123809381 @@ -48,7 +50,7 @@ Random: 146808189 If you prefer to choose your own prime number (from [this list](http://primes.utm.edu/lists/small/millions/) for example), you can pass it to the command to calculate the remaining numbers: -``` +```bash > php vendor/bin/optimus spark 1580030173 Prime: 1580030173 @@ -135,16 +137,16 @@ More information: https://laravel.com/docs/5.3/container#resolving **Third-party integrations** -An integration with Laravel is provided by the [propaganistas/laravel-fakeid](https://packagist.org/packages/propaganistas/laravel-fakeid) package. - -Laravel Optimus with multiple connections provided by the [cybercog/laravel-optimus](https://github.com/cybercog/laravel-optimus) package. - -An integration with Silex 2 is provided by the [jaam/silex-optimus-provider](https://packagist.org/packages/jaam/silex-optimus-provider) package. - -An integration with Laravel is provided by the [elfsundae/laravel-hashid](https://github.com/ElfSundae/laravel-hashid) package. - -A PSR-15 middleware provided by the [icanhazstring/optimus-middleware](https://github.com/icanhazstring/optimus-middleware) package. +* An integration with Laravel is provided by the [propaganistas/laravel-fakeid](https://packagist.org/packages/propaganistas/laravel-fakeid) package. +* Laravel Optimus with multiple connections provided by the [cybercog/laravel-optimus](https://github.com/cybercog/laravel-optimus) package. +* An integration with Silex 2 is provided by the [jaam/silex-optimus-provider](https://packagist.org/packages/jaam/silex-optimus-provider) package. +* An integration with Laravel is provided by the [elfsundae/laravel-hashid](https://github.com/ElfSundae/laravel-hashid) package. +* A PSR-15 middleware provided by the [icanhazstring/optimus-middleware](https://github.com/icanhazstring/optimus-middleware) package. ## Security contact information To report a security vulnerability, follow [these steps](https://tidelift.com/security). + +## License + +The [MIT](https://opensource.org/licenses/MIT) License. \ No newline at end of file diff --git a/composer.json b/composer.json index 8b9879d..01a4185 100644 --- a/composer.json +++ b/composer.json @@ -32,5 +32,12 @@ "suggest": { "ext-gmp": "Required for 32bit systems" }, - "bin": ["bin/optimus"] + "bin": ["bin/optimus"], + "config": { + "sort-packages": true, + "preferred-install": "dist" + }, + "scripts": { + "test": "vendor/bin/phpunit --testdox --color=always" + } } diff --git a/tests/EnergonTest.php b/tests/EnergonTest.php index 5f4be5b..90a8e32 100644 --- a/tests/EnergonTest.php +++ b/tests/EnergonTest.php @@ -33,9 +33,9 @@ public function testGeneratesRandomSet(int $bitLength) $set = Energon::generate(null, $bitLength); $this->assertCount(3, $set); - $this->assertInternalType('integer', $set[0], 'Unexpected type for prime number.'); - $this->assertInternalType('integer', $set[1], 'Unexpected type for inverse number.'); - $this->assertInternalType('integer', $set[2], 'Unexpected type for Xor.'); + $this->assertIsInt($set[0], 'Unexpected type for prime number.'); + $this->assertIsInt($set[1], 'Unexpected type for inverse number.'); + $this->assertIsInt($set[2], 'Unexpected type for Xor.'); $this->assertSame( '1', (new BigInteger($set[0])) @@ -70,9 +70,9 @@ public function testGeneratesAskedSet(int $bitLength, int $prime, int $expectedI $set = Energon::generate($prime, $bitLength); $this->assertCount(3, $set); - $this->assertInternalType('integer', $set[0], 'Unexpected type for prime number.'); - $this->assertInternalType('integer', $set[1], 'Unexpected type for inverse number.'); - $this->assertInternalType('integer', $set[2], 'Unexpected type for Xor.'); + $this->assertIsInt($set[0], 'Unexpected type for prime number.'); + $this->assertIsInt($set[1], 'Unexpected type for inverse number.'); + $this->assertIsInt($set[2], 'Unexpected type for Xor.'); $this->assertEquals($prime, $set[0], 'Unexpected prime number.'); $this->assertEquals($expectedInverse, $set[1], 'Unexpected inverse number.'); }