Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/365054 )
Change subject: Add Guid related methods to `NewStatement`
......................................................................
Add Guid related methods to `NewStatement`
Change-Id: Ief497288f19c69e11295659492568ef4c794b951
---
M repo/tests/phpunit/includes/NewStatement.php
1 file changed, 55 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/54/365054/1
diff --git a/repo/tests/phpunit/includes/NewStatement.php
b/repo/tests/phpunit/includes/NewStatement.php
index a3860d7..bc206a8 100644
--- a/repo/tests/phpunit/includes/NewStatement.php
+++ b/repo/tests/phpunit/includes/NewStatement.php
@@ -15,6 +15,8 @@
class NewStatement {
+ const GENERATE_GUID = true;
+
/**
* @var PropertyId
*/
@@ -34,6 +36,8 @@
* @var int
*/
private $rank = Statement::RANK_NORMAL;
+
+ private $guid;
/**
* @param PropertyId|string $propertyId
@@ -117,6 +121,35 @@
return $this->withRank( Statement::RANK_PREFERRED );
}
+ /**
+ * @param string $guid
+ * @return self
+ */
+ public function withGuid( $guid ) {
+ $result = clone $this;
+ if ( $result->guid !== null ) {
+ throw new \LogicException( 'Cannot redefine GUID' );
+ }
+
+ $result->guid = (string)$guid;
+
+ return $result;
+ }
+
+ /**
+ * @return self
+ */
+ public function withSomeGuid() {
+ $result = clone $this;
+ if ( $result->guid !== null ) {
+ throw new \LogicException( 'Cannot redefine GUID' );
+ }
+
+ $result->guid = self::GENERATE_GUID;
+
+ return $result;
+ }
+
private function __construct() {
}
@@ -148,7 +181,29 @@
$result = new Statement( $snack );
$result->setRank( $this->rank );
+ if ( $this->guid ) {
+ if ( $this->guid === self::GENERATE_GUID ) {
+ $result->setGuid( $this->generateUuidV4() );
+ } else {
+ $result->setGuid( $this->guid );
+ }
+ }
+
return $result;
}
+ private function generateUuidV4() {
+ return sprintf(
+ '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
+ mt_rand( 0, 0xffff ),
+ mt_rand( 0, 0xffff ),
+ mt_rand( 0, 0xffff ),
+ mt_rand( 0, 0x0fff ) | 0x4000,
+ mt_rand( 0, 0x3fff ) | 0x8000,
+ mt_rand( 0, 0xffff ),
+ mt_rand( 0, 0xffff ),
+ mt_rand( 0, 0xffff )
+ );
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/365054
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ief497288f19c69e11295659492568ef4c794b951
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits