semantic versioning.php
1.1.0
ห้องสมุดอิสระขนาดเล็กสำหรับการแยกวิเคราะห์และเปรียบเทียบเวอร์ชันความหมายซึ่งเข้ากันได้กับเวอร์ชันความหมาย 2.0
ดาวน์โหลด Composer และติดตั้ง rayne/semantic-versioning
composer require rayne/semantic-versioning
โคลนที่เก็บ
git clone https://github.com/rayne/semantic-versioning.php.git
ติดตั้งการพัฒนาการพัฒนา
composer install --dev
เรียกใช้การทดสอบ
./vendor/bin/phpunit
ห้องสมุดมีคลาสต่อไปนี้:
InvalidVersionException : โยนโดย SemanticVersion บนอินพุตที่ไม่ถูกต้อง
SemanticComparator : ตัวเปรียบเทียบเวอร์ชันความหมายสำหรับการเปรียบเทียบวัตถุ SemanticVersion
SemanticVersion : ตัวแยกวิเคราะห์เวอร์ชันความหมายซึ่งพุ่งเข้าหา RuntimeException ในเวอร์ชันที่ไม่ถูกต้อง
ตัวอย่างเป็นส่วนหนึ่งของชุดทดสอบ ดูไดเรกทอรี tests สำหรับข้อมูลเพิ่มเติม
use Rayne SemanticVersioning SemanticVersion ;
$ version = new SemanticVersion ( ' 1.0.0-beta+exp.sha.5114f85 ' );
assert ( ' 1.0.0-beta+exp.sha.5114f85 ' === ( string ) $ version );
assert ( 1 === $ version -> getMajor ());
assert ( 0 === $ version -> getMinor ());
assert ( 0 === $ version -> getPatch ());
assert ( ' beta ' === $ version -> getPre ());
assert ( ' exp.sha.5114f85 ' === $ version -> getMeta ());
assert ( ' 1.0.0-beta+exp.sha.5114f85 ' === $ version -> getVersion ());
assert ( true === $ version -> isMajorRelease ());
assert ( false === $ version -> isMinorRelease ());
assert ( false === $ version -> isPatchRelease ());
assert ( true === $ version -> isPreRelease ()); use Rayne SemanticVersioning SemanticComparator ;
use Rayne SemanticVersioning SemanticVersion ;
$ comparator = new SemanticComparator ;
$ alpha = new SemanticVersion ( ' 1.0.0-alpha ' );
$ candidate = new SemanticVersion ( ' 1.0.0-rc.1 ' );
$ candidate_meta = new SemanticVersion ( ' 1.0.0-rc.1+ci ' );
$ release = new SemanticVersion ( ' 1.0.0 ' );
// $alpha < $candidate
assert ( $ comparator ( $ alpha , $ candidate ) < 0 );
assert ( $ comparator -> compare ( $ alpha , $ candidate ) < 0 );
// $candidate == $candidate_meta
assert ( $ comparator ( $ candidate , $ candidate_meta ) == 0 );
assert ( $ comparator -> compare ( $ candidate , $ candidate_meta ) == 0 );
// $release > $candidate
assert ( $ comparator ( $ release , $ candidate ) > 0 );
assert ( $ comparator -> compare ( $ release , $ candidate ) > 0 ); use Rayne SemanticVersioning SemanticComparator ;
use Rayne SemanticVersioning SemanticVersion ;
$ versions = [
$ candidate = new SemanticVersion ( ' 1.0.0-rc.1 ' ),
$ release = new SemanticVersion ( ' 1.0.0 ' ),
$ alpha = new SemanticVersion ( ' 1.0.0-alpha ' ),
];
// Sort by semantic precedence.
usort ( $ versions , new SemanticComparator );
assert ( $ versions [ 0 ] === $ alpha );
assert ( $ versions [ 1 ] === $ candidate );
assert ( $ versions [ 2 ] === $ release );