Skip to content

Commit

Permalink
Add missing test for Code class
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Dec 30, 2023
1 parent 6b31bef commit 12a4cde
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/test/php/com/mongodb/unittest/CodeTest.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php namespace com\mongodb\unittest;

use com\mongodb\Code;
use test\{Assert, Test};

class CodeTest {
const SOURCE= 'console.log("Test")';

#[Test]
public function can_create() {
new Code(self::SOURCE);
}

#[Test]
public function source() {
Assert::equals(self::SOURCE, (new Code(self::SOURCE))->source());
}

#[Test]
public function length() {
Assert::equals(strlen(self::SOURCE), (new Code(self::SOURCE))->length());
}

#[Test]
public function hash_of() {
Assert::equals('JS2892344631', (new Code(self::SOURCE))->hashCode());
}

#[Test]
public function string_representation() {
Assert::equals('com.mongodb.Code(`console.log("Test")`)', (new Code(self::SOURCE))->toString());
}

#[Test]
public function string_cast() {
Assert::equals(self::SOURCE, (string)new Code(self::SOURCE));
}

#[Test]
public function compare() {
Assert::equals(0, (new Code(self::SOURCE))->compareTo(new Code(self::SOURCE)));
Assert::equals(1, (new Code(self::SOURCE))->compareTo(new Code('')));
}
}

0 comments on commit 12a4cde

Please sign in to comment.