57 Commits

Author SHA1 Message Date
zedar187 77e33bc7be feat(SystemNodeProvider): dismiss zero'd mac address (#468)
Co-authored-by: Ben Ramsey <ben@benramsey.com>
2022-12-19 15:30:41 -06:00
Marco Pivetta f0ada112c5 Allow iterable<T> where ramsey/collection would be used, deprecate collection classes
This patch is based on https://github.com/ramsey/uuid/pull/405

As discussed in https://github.com/ramsey/uuid/pull/405#discussion_r832095457, the `ramsey/collection`
dependency can be phased out.

Doing so via direct removal is not feasible without a clear BC break, so this change only deprecates:

 * `Ramsey\Uuid\Builder\BuilderCollection`
 * `Ramsey\Uuid\Provider\Node\NodeProviderCollection`

These classes will then be removed in `5.0.0`, along with the `ramsey/collection` dependency.
2022-03-22 17:30:42 +01:00
Marco Pivetta 5f9cd80b1b Migrated from PHPUnit_Framework_TestCase#assertRegExp() (deprecated) to #assertMatchesRegularExpression() 2022-03-22 12:43:22 +01:00
Ben Ramsey c005f69d6e chore: update package files 2021-08-06 14:05:57 -05:00
Ben Ramsey b941aa1a9a Prepare test suite for PHP 8 2020-10-29 18:24:14 -05:00
Bilge 7947413a76 Use assertSame instead of assertEquals. 2020-08-23 13:53:19 +01:00
Ben Ramsey ba8fff1d3a Fix collection deserialization errors 2020-03-29 15:13:32 -05:00
Ben Ramsey fcfcd3fb60 Fix failing tests on Windows
escapeshellargs() uses different quotation mark characters between Linux
and Windows, so tests were failing on Windows. This change uses a
regular expression instead.
2020-03-17 11:43:45 -05:00
Ben Ramsey b3c26661ca Correct capitalization of microsecond 2020-03-04 16:51:46 -06:00
Ben Ramsey 86c37eff4c Change NodeProviderInterface::getNode() to return Hexadecimal 2020-02-29 22:35:45 -06:00
Ben Ramsey 4ffd156a84 Add StaticNodeProvider to make it easier to use a static node 2020-02-29 17:23:27 -06:00
Ben Ramsey 0bd312f944 Improve test coverage 2020-02-26 20:17:49 -06:00
Ben Ramsey 84a2e76c7e Remove currentTime() method 2020-02-23 16:11:50 -06:00
Ben Ramsey aaccc850a1 Use strict argument validation for collections
This resolves #106
2020-02-23 00:50:00 -06:00
Ben Ramsey f42afcecbb Rename Type\IntegerValue to Type\Integer
Rename `Type\IntegerValue` to `Type\Integer`. It was originally named
`IntegerValue` because static analysis sees `Integer` in docblock
annotations and treats it as the native `int` type. `Integer` is not a
reserved word in PHP, so it should be named `Integer` for consistency
with other types in this library. When using it, a class alias prevents
static analysis from complaining.
2020-02-21 11:59:49 -06:00
Ben Ramsey fb4f54fb84 Address static analysis issues 2020-02-08 13:14:17 -06:00
Ben Ramsey e5357f2c8a Add missing native type hints to test method 2020-02-03 16:07:38 -06:00
Ben Ramsey 2e420f94c4 Revert "Suppress MissingNativeTypeHint error from slevomat/coding-standard"
This reverts commit e269c16cd4.

This issue is fixed in slevomat/coding-standard 6.1.4. See thread at
https://github.com/slevomat/coding-standard/issues/883
2020-02-03 16:01:43 -06:00
Marco Pivetta a252f29847 Import used functions and constants via use statement to disallow ambiguity for compiler/static-analysis
As documented in https://wiki.php.net/rfc/use_global_elements, the engine (by default) does a local namespace
lookup, then falls back to global namespace when first calling a global function referenced in namespaced code,
unless that function is referenced via fully qualified name (FQN).

By using the FQN, the actual symbol can be looked up at compile-time, both by the PHP engine and by static analysis
tooling, allowing for compiler (in particular) optimizations to replace known hot-path functions with specialized opcodes.

Sadly, no actual benchmark at hand: the improvements can be minimal or massive, depending on where this library is
used (tight loops being most relevant).
2020-02-03 13:15:35 -06:00
Ben Ramsey e269c16cd4 Suppress MissingNativeTypeHint error from slevomat/coding-standard 2020-02-02 18:38:03 -06:00
Ben Ramsey 72a2312f62 Support generation of version 2 (DCE Security) UUIDs 2020-01-18 12:14:01 -06:00
Ben Ramsey 4125885862 Add getTime() to TimeProviderInterface and mark currentTime() deprecated 2020-01-18 12:13:58 -06:00
Ben Ramsey 12896f06db Use internal exceptions
Fixes #254
2020-01-18 12:13:55 -06:00
Ben Ramsey 0d7b8c2b7a Update coding style to include PSR-12, among other options
This also includes heavy use of slevomat/coding-standard to apply
various checks to the code, based on maintainer (me) preference.
2020-01-18 12:13:55 -06:00
Ben Ramsey 81f0f9a9b4 Clean-up tests and use PHPStan max level for tests 2020-01-18 12:13:09 -06:00
SignpostMarv 0030399564 Increase PHPStan levels and update code to resolve issues found 2020-01-18 12:13:08 -06:00
Martin Hujer ca2629767d Require phpstan and correct issues found up to level 2
* issues found by phpstan L0
* issues found by phpstan L1
* issues found by phpstan L2 in src/
* issues found by phpstan L2 in tests/
2020-01-18 12:13:08 -06:00
Ben Ramsey 5d7ee63f1c Update dev requirements and test suite for PHP 7+ only 2020-01-18 12:13:07 -06:00
Jildert Miedema 225eb3b4c1 Set minimum version to PHP 5.6 and use PHP 5.5 style ::class constants 2020-01-18 12:13:07 -06:00
Ben Ramsey b39ec78f6e Check whether sysfs is readable before attempting to read it
Fixes #260
2019-12-17 02:01:14 -06:00
Ben Ramsey 692175901d Fix RandomNodeProvider behavior on 32-bit systems
The 6 bytes obtained from `random_bytes()` is a 48-bit integer, which
cannot be converted to decimal on a 32-bit system, without being
implicitly cast to a float by PHP. This was causing problems with
setting the multicast bit, and it led to non-random node values.

This new approach splits the 6 bytes up into two 3-byte values, each a
24-bit integer, and applies the multicast bit to the most significant
bits before re-combining the bytes as a string.
2019-11-30 20:26:42 -08:00
Ben Ramsey 64ba9a2767 Clean up code according to PhpStorm inspections report 2019-11-30 13:14:52 -08:00
Ben Ramsey 555e5c1102 Test usage of PHP_OS constant 2019-11-30 12:18:43 -08:00
Ben Ramsey 657add4b3c Fix mock invocation assertions 2019-11-30 09:10:09 -08:00
Martin Hujer f3e0fed2d7 Drop remnants of HHVM from tests
It was removed from Travis in c479cdd42f
2019-11-30 09:10:09 -08:00
Ben Ramsey 93a19b8133 Fix failing build due to coding standards violation 2018-07-19 17:19:38 -05:00
Ben Ramsey 8d621488c4 Check whether passthru() is disabled
If passthru() is disabled in php.ini, this will force the
SystemNodeProvider to return `false` for the node. Using the default
FallbackNodeProvider, ramsey/uuid will default to the
RandomNodeProvider, in these cases.

Closes #114
2018-07-19 16:53:00 -05:00
Ben Ramsey b8cac9278c Merge branch 'SystemNodeProvider-FreeBSD-support' of https://github.com/kalifg/uuid into kalifg-SystemNodeProvider-FreeBSD-support 2018-07-19 15:08:45 -05:00
Ben Peachey 62628862df Improvements to the SystemNodeProviderTest class (#211)
* Changes location of providers in the SystemNodeProviderTest

  They are now grouped at the bottom of the class.

* Adds logic to SystemNodeProviderTest.

* Changes call to `file_get_contents` SystemNodeProvider so it can be
  mocked.

* Changes SystemNodeProviderTest so native PHP functions are mocked
  instead of the class under test.

* Changes SystemNodeProviderTest so "\n" is used instead of PHP_EOL

  As the (input or output) of the tests is not system dependant it does
  not make sense to use PHP_EOL. All of these instance have been
  replaced for the sake of readability and stating intent more clearly.

* Adds dataprovider to SystemNodeProvider main test for input
  variations.

* Adds OS to SystemNodeProviderTest dataprovider for Linux fail
  scenario.

* Adds test for SystemNodeProvider to ensure invalid values are not
  accepted.

* Changes names of dataproviders in SystemNodeProviderTest for
  consistency.

* Changes SystemNodeProviderTest by grouping dataproviders together.

* Changes method in SystemNodeProviderTest to use the provided mock
  functions.

* Fixes PSR-2 coding conventions in SystemNodeProviderTest.

* Minor change to SystemNodeProviderTest based on review.
2018-02-07 17:28:02 -06:00
kalifg a7492800e2 Add support for determining MAC address on FreeBSD systems 2018-02-07 15:15:49 -06:00
Ben Ramsey f203f13921 Fix broken build on PHP 5.4 2018-01-19 16:00:06 -06:00
Ben Ramsey e67d6bfdc2 Revert to pre-1.x series of mockery/mockery for ramsey/uuid 3.x 2018-01-16 19:45:47 -06:00
Ben Ramsey 89c3c1777e Fix capitalization of the getSysfs() method 2018-01-16 14:14:34 -06:00
Ben Ramsey 901c3e540d Handle cases where glob() returns false
Fixes #203
2018-01-16 14:11:58 -06:00
Gabriel Caruso f65471fb5c Use assertSame 2017-12-10 05:51:10 -02:00
Robbert Müller 8a540b78a1 mock glob function to get assertions work 2017-11-17 16:16:29 +01:00
Robbert Müller 70346f5da3 Fix whitespace 2017-11-17 15:00:23 +01:00
Robbert Müller a9154c4c27 add testcase for getsysfs 2017-11-17 14:52:51 +01:00
Ben Ramsey 6b0445588c Merge branch 'master' into add-sysfs-option 2017-11-10 16:04:30 -06:00
Robbert Müller 3572bf8755 adapt testcases to also mock getsysfs, to get the old code path tested 2017-10-18 11:33:26 +02:00