Exemple #1
0
 private function processElements($elements)
 {
     $requestedElements = NULL;
     if (FALSE === is_array($elements) || FALSE === $elements instanceof \Iterator) {
         throw new InvalidElementContainerException();
     }
     if (TRUE === is_array($elements) || TRUE === $elements instanceof \Countable) {
         $requestedElements = count($elements);
     }
     if (NULL !== $requestedElements && $requestedElements > $this->size->value()) {
         throw new OffsetToLargeException($this->size->value(), $requestedElements);
     }
     foreach ($elements as $element) {
         $this->processSingleElement($element);
     }
 }
Exemple #2
0
 /**
  * @covers ::generate()
  */
 public function testGenerateProperValue()
 {
     $randomString5 = RandomString::generate(Integer::get(5));
     $this->assertEquals(5, strlen($randomString5->value()));
     $randomString5 = RandomString::generate(Integer::get(900));
     $this->assertEquals(900, strlen($randomString5->value()));
 }
Exemple #3
0
 /**
  * @param \AGmakonts\STL\String\Text $date
  * @param \AGmakonts\STL\String\Text $format
  *
  * @return DateTime
  */
 public static function getFromFormat(Text $date, Text $format)
 {
     $dateTime = \DateTime::createFromFormat($format->value(), $date->value());
     if (FALSE === $dateTime) {
         throw new \InvalidArgumentException("Wrong format or date provided");
     }
     $timestamp = Integer::get($dateTime->getTimestamp());
     return self::getInstanceForValue($timestamp);
 }
 /**
  * @return \AGmakonts\STL\DateTime\DateTime
  */
 public function nextAnniversary() : DateTime
 {
     $nativeDate = new \DateTime($this->date()->getTimestamp()->value());
     $now = new \DateTime();
     $interval = new \DateInterval('P1Y');
     while ($nativeDate->getTimestamp() < $now->getTimestamp()) {
         $nativeDate = $nativeDate->add($interval);
     }
     return DateTime::get(Integer::get($nativeDate->getTimestamp()));
 }
Exemple #5
0
 /**
  * @param $string
  * @param $length
  * @param $fill
  * @param $mode
  * @param $expected
  *
  * @covers ::padded
  * @dataProvider paddedProvider
  */
 public function testPadded($string, $length, $fill, $mode, $expected)
 {
     $string = Text::get($string);
     $length = Integer::get($length);
     if (NULL !== $fill) {
         $fill = Text::get($fill);
     }
     $mode = \AGmakonts\STL\String\Padding::get($mode);
     self::assertEquals($expected, $string->padded($length, $mode, $fill)->value());
 }
Exemple #6
0
 /**
  * @return Sign
  */
 public function sign()
 {
     return Sign::get(intval($this->isLessThan(Integer::get())));
 }
Exemple #7
0
 /**
  * @covers ::getTimestamp()
  */
 public function testGetTimestamp()
 {
     $testClass1 = \AGmakonts\STL\DateTime\DateTime::get(Integer::get(1));
     $this->assertInstanceOf(Integer::class, $testClass1->getTimestamp());
     $this->assertEquals(1, $testClass1->getTimestamp()->value());
 }
Exemple #8
0
 /**
  * @param \AGmakonts\STL\Number\Integer  $position
  *
  * @return \AGmakonts\STL\String\Text
  */
 public function charAtPosition(Integer $position)
 {
     $one = Integer::get(1);
     return $this->substr($position->subtract($one), $one);
 }
Exemple #9
0
 public function testModulo()
 {
     $decimal = Decimal::get(5);
     $result = $decimal->modulo(Integer::get(4));
     $this->assertEquals(1, $result->value());
 }
Exemple #10
0
 /**
  * @dataProvider decrementIncrementDataProvider
  * @covers ::increment
  */
 public function testIncrement($value)
 {
     $int = \AGmakonts\STL\Number\Integer::get($value);
     $int = $int->increment();
     self::assertTrue($value + 1 === $int->value());
 }