Skip to content
Permalink
Browse files

Str coverage

  • Loading branch information
rodolfoberrios committed Feb 11, 2020
1 parent a968e9b commit f0ddc759eef5a049ac7200f5aba99bac044c1f87
Showing with 242 additions and 110 deletions.
  1. +118 −109 .vscode/Templates.code-snippets
  2. +1 −0 README.md
  3. +1 −1 components/Str/Str.php
  4. +122 −0 components/Str/Tests/StrTest.php
@@ -1,110 +1,119 @@
{
"interface": {
"description": "inserts a new interface",
"prefix": "interface",
"body": [
"<?php",
"namespace Chevere\\Components\\X\\Interfaces;",
"",
"interface NameInterface",
"{",
"}"
]
},
"test": {
"description": "inserts a new test",
"prefix": "test",
"body": [
"<?php",
"namespace Chevere\\Components\\X\\Tests;",
"",
"use PHPUnit\\Framework\\TestCase;",
"",
"final class NameTest extends TestCase",
"{",
"}"
]
},
"class": {
"description": "inserts a new class",
"prefix": "class",
"body": [
"<?php",
"namespace Chevere\\Components\\X;",
"",
"final class Name",
"{",
"}"
]
},
"constructor": {
"description": "inserts a constructor",
"prefix": "constructor",
"body": ["\tpublic function __construct()", "\t{", "\t", "\t}"]
},
"exception": {
"description": "inserts a exception",
"prefix": "exception",
"body": [
"<?php",
"namespace Chevere\\Components\\X\\Exceptions;",
"",
"use Exception;",
"",
"/**",
" * Exception thrown when _____.",
" */",
"final class NameException extends Exception",
"{",
"}"
]
},
"trait": {
"description": "inserts a trait",
"prefix": "trait",
"body": [
"<?php",
"namespace Chevere\\Components\\X\\Traits;",
"",
"trait NameTrait",
"{",
"}"
]
},
"docblock-construct": {
"description": "inserts a docblock construct",
"prefix": "docblock-construct",
"body": ["/**", " * Creates a new instance.", " */"]
},
"docblock-inherith": {
"description": "inserts a docblock @inherith",
"prefix": "docblock-inherith",
"body": ["/**", " * {@inheritdoc}", " */"]
},
"docblock-instance": {
"description": "inserts a docblock instance",
"prefix": "docblock-instance",
"body": ["/**", " * Provides access to the X instance.", " */"]
},
"docblock-inmutable": {
"description": "inserts a docblock inmutable",
"prefix": "docblock-inmutable",
"body": [
"/**",
" * Return an instance with the specified X.",
" *",
" * This method MUST retain the state of the current instance, and return",
" * an instance that contains the specified X.",
" */"
]
},
"docblock-boolean": {
"description": "inserts a docblock boolean",
"prefix": "docblock-boolean",
"body": [
"/**",
" * Returns a boolean indicating whether the instance has a X.",
" */"
]
}
}
"interface": {
"description": "inserts a new interface",
"prefix": "interface",
"body": [
"<?php",
"namespace Chevere\\Components\\X\\Interfaces;",
"",
"interface NameInterface",
"{",
"}"
]
},
"test": {
"description": "inserts a new test",
"prefix": "test",
"body": [
"<?php",
"namespace Chevere\\Components\\X\\Tests;",
"",
"use PHPUnit\\Framework\\TestCase;",
"",
"final class NameTest extends TestCase",
"{",
"}"
]
},
"test-method": {
"description": "inserts a new test method",
"prefix": "test-method",
"body": [
"public function testX(): void",
"{",
"}"
]
},
"class": {
"description": "inserts a new class",
"prefix": "class",
"body": [
"<?php",
"namespace Chevere\\Components\\X;",
"",
"final class Name",
"{",
"}"
]
},
"constructor": {
"description": "inserts a constructor",
"prefix": "constructor",
"body": ["\tpublic function __construct()", "\t{", "\t", "\t}"]
},
"exception": {
"description": "inserts a exception",
"prefix": "exception",
"body": [
"<?php",
"namespace Chevere\\Components\\X\\Exceptions;",
"",
"use Exception;",
"",
"/**",
" * Exception thrown when _____.",
" */",
"final class NameException extends Exception",
"{",
"}"
]
},
"trait": {
"description": "inserts a trait",
"prefix": "trait",
"body": [
"<?php",
"namespace Chevere\\Components\\X\\Traits;",
"",
"trait NameTrait",
"{",
"}"
]
},
"docblock-construct": {
"description": "inserts a docblock construct",
"prefix": "docblock-construct",
"body": ["/**", " * Creates a new instance.", " */"]
},
"docblock-inherith": {
"description": "inserts a docblock @inherith",
"prefix": "docblock-inherith",
"body": ["/**", " * {@inheritdoc}", " */"]
},
"docblock-instance": {
"description": "inserts a docblock instance",
"prefix": "docblock-instance",
"body": ["/**", " * Provides access to the X instance.", " */"]
},
"docblock-inmutable": {
"description": "inserts a docblock inmutable",
"prefix": "docblock-inmutable",
"body": [
"/**",
" * Return an instance with the specified X.",
" *",
" * This method MUST retain the state of the current instance, and return",
" * an instance that contains the specified X.",
" */"
]
},
"docblock-boolean": {
"description": "inserts a docblock boolean",
"prefix": "docblock-boolean",
"body": [
"/**",
" * Returns a boolean indicating whether the instance has a X.",
" */"
]
}
}
@@ -1,5 +1,6 @@
[![Scrutinizer Code
Quality](https://scrutinizer-ci.com/g/chevere/chevere/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/chevere/chevere/?branch=master)
[![codecov](https://codecov.io/gh/chevere/chevere/branch/master/graph/badge.svg)](https://codecov.io/gh/chevere/chevere)
[![CodeFactor](https://www.codefactor.io/repository/github/chevere/chevere/badge)](https://www.codefactor.io/repository/github/chevere/chevere)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/b956754f8ff04aaa9ca24a6e4cc21661)](https://www.codacy.com/gh/chevere/chevere?utm_source=github.com&utm_medium=referral&utm_content=chevere/chevere&utm_campaign=Badge_Grade)
[![Maintainability](https://api.codeclimate.com/v1/badges/e096f89454df0538144f/maintainability)](https://codeclimate.com/github/chevere/chevere/maintainability)
@@ -55,7 +55,7 @@ public function stripExtraWhitespace(): StrInterface

public function stripNonAlphanumerics(): StrInterface
{
$this->string = preg_replace('/[^[:alnum:][:space:]]/u', '', $this->string) ?? '';
$this->string = preg_replace('/[^[:alnum:]]/u', '', $this->string) ?? '';

return $this;
}
@@ -0,0 +1,122 @@
<?php

/*
* This file is part of Chevere.
*
* (c) Rodolfo Berrios <rodolfo@chevere.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Chevere\Components\Str\Tests;

use Chevere\Components\Str\Str;
use PHPUnit\Framework\TestCase;

final class StrTest extends TestCase
{
public function testToString(): void
{
$string = 'string';
$this->assertSame($string, (string) new Str($string));
}

public function testLowercase(): void
{
$string = 'sTrÍnG';
$expected = 'stríng';
$this->assertSame(
$expected,
(string) (new Str($string))->lowercase()
);
}

public function testStripWhitespace(): void
{
$string = 'st ri ng';
$expected = 'string';
$this->assertSame(
$expected,
(string) (new Str($string))->stripWhitespace()
);
}

public function testStripExtraWhitespace(): void
{
$string = 'str in g';
$expected = 'str in g';
$this->assertSame(
$expected,
(string) (new Str($string))->stripExtraWhitespace()
);
}

public function testStripNonAlphanumerics(): void
{
$string = '$7r |n,;:g! %~';
$expected = '7rng';
$this->assertSame(
$expected,
(string) (new Str($string))->stripNonAlphanumerics()
);
}

public function testForwardSlashes(): void
{
$string = '\\str\in\\\\g';
$expected = '/str/in//g';
$this->assertSame(
$expected,
(string) (new Str($string))->forwardSlashes()
);
}

public function testLeftTail(): void
{
$string = 'string';
$tail = 'lt';
$expected = $tail . $string;
$this->assertSame(
$expected,
(string) (new Str($tail . $tail . $string))->leftTail($tail)
);
}

public function testRightTail(): void
{
$string = 'string';
$tail = 'rt';
$expected = $string . $tail;
$this->assertSame(
$expected,
(string) (new Str($string . $tail . $tail))->rightTail($tail)
);
}

public function testReplaceFirst(): void
{
$string = 'ststring';
$search = 'st';
$replace = 'the ';
$expected = 'the string';
$this->assertSame(
$expected,
(string) (new Str($string))->replaceFirst($search, $replace)
);
}

public function testReplaceLast(): void
{
$string = 'stringg';
$search = 'g';
$replace = 'o';
$expected = 'stringo';
$this->assertSame(
$expected,
(string) (new Str($string))->replaceLast($search, $replace)
);
}
}

0 comments on commit f0ddc75

Please sign in to comment.
You can’t perform that action at this time.