File: IsCamelCapsTest.php

package info (click to toggle)
php-codesniffer 3.11.2-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 13,772 kB
  • sloc: php: 84,771; pascal: 10,061; xml: 6,832; javascript: 2,096; sh: 11; makefile: 4
file content (140 lines) | stat: -rw-r--r-- 4,892 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
 * Tests for the \PHP_CodeSniffer\Util\Common::isCamelCaps method.
 *
 * @author    Greg Sherwood <gsherwood@squiz.net>
 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
 * @license   https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
 */

namespace PHP_CodeSniffer\Tests\Core\Util\Common;

use PHP_CodeSniffer\Util\Common;
use PHPUnit\Framework\TestCase;

/**
 * Tests for the \PHP_CodeSniffer\Util\Common::isCamelCaps method.
 *
 * @covers \PHP_CodeSniffer\Util\Common::isCamelCaps
 */
final class IsCamelCapsTest extends TestCase
{


    /**
     * Test valid public function/method names.
     *
     * @return void
     */
    public function testValidNotClassFormatPublic()
    {
        $this->assertTrue(Common::isCamelCaps('thisIsCamelCaps', false, true, true));
        $this->assertTrue(Common::isCamelCaps('thisISCamelCaps', false, true, false));

    }//end testValidNotClassFormatPublic()


    /**
     * Test invalid public function/method names.
     *
     * @return void
     */
    public function testInvalidNotClassFormatPublic()
    {
        $this->assertFalse(Common::isCamelCaps('_thisIsCamelCaps', false, true, true));
        $this->assertFalse(Common::isCamelCaps('thisISCamelCaps', false, true, true));
        $this->assertFalse(Common::isCamelCaps('ThisIsCamelCaps', false, true, true));

        $this->assertFalse(Common::isCamelCaps('3thisIsCamelCaps', false, true, true));
        $this->assertFalse(Common::isCamelCaps('*thisIsCamelCaps', false, true, true));
        $this->assertFalse(Common::isCamelCaps('-thisIsCamelCaps', false, true, true));

        $this->assertFalse(Common::isCamelCaps('this*IsCamelCaps', false, true, true));
        $this->assertFalse(Common::isCamelCaps('this-IsCamelCaps', false, true, true));
        $this->assertFalse(Common::isCamelCaps('this_IsCamelCaps', false, true, true));
        $this->assertFalse(Common::isCamelCaps('this_is_camel_caps', false, true, true));

    }//end testInvalidNotClassFormatPublic()


    /**
     * Test valid private method names.
     *
     * @return void
     */
    public function testValidNotClassFormatPrivate()
    {
        $this->assertTrue(Common::isCamelCaps('_thisIsCamelCaps', false, false, true));
        $this->assertTrue(Common::isCamelCaps('_thisISCamelCaps', false, false, false));
        $this->assertTrue(Common::isCamelCaps('_i18N', false, false, true));
        $this->assertTrue(Common::isCamelCaps('_i18n', false, false, true));

    }//end testValidNotClassFormatPrivate()


    /**
     * Test invalid private method names.
     *
     * @return void
     */
    public function testInvalidNotClassFormatPrivate()
    {
        $this->assertFalse(Common::isCamelCaps('thisIsCamelCaps', false, false, true));
        $this->assertFalse(Common::isCamelCaps('_thisISCamelCaps', false, false, true));
        $this->assertFalse(Common::isCamelCaps('_ThisIsCamelCaps', false, false, true));
        $this->assertFalse(Common::isCamelCaps('__thisIsCamelCaps', false, false, true));
        $this->assertFalse(Common::isCamelCaps('__thisISCamelCaps', false, false, false));

        $this->assertFalse(Common::isCamelCaps('3thisIsCamelCaps', false, false, true));
        $this->assertFalse(Common::isCamelCaps('*thisIsCamelCaps', false, false, true));
        $this->assertFalse(Common::isCamelCaps('-thisIsCamelCaps', false, false, true));
        $this->assertFalse(Common::isCamelCaps('_this_is_camel_caps', false, false, true));

    }//end testInvalidNotClassFormatPrivate()


    /**
     * Test valid class names.
     *
     * @return void
     */
    public function testValidClassFormatPublic()
    {
        $this->assertTrue(Common::isCamelCaps('ThisIsCamelCaps', true, true, true));
        $this->assertTrue(Common::isCamelCaps('ThisISCamelCaps', true, true, false));
        $this->assertTrue(Common::isCamelCaps('This3IsCamelCaps', true, true, false));

    }//end testValidClassFormatPublic()


    /**
     * Test invalid class names.
     *
     * @return void
     */
    public function testInvalidClassFormat()
    {
        $this->assertFalse(Common::isCamelCaps('thisIsCamelCaps', true));
        $this->assertFalse(Common::isCamelCaps('This-IsCamelCaps', true));
        $this->assertFalse(Common::isCamelCaps('This_Is_Camel_Caps', true));

    }//end testInvalidClassFormat()


    /**
     * Test invalid class names with the private flag set.
     *
     * Note that the private flag is ignored if the class format
     * flag is set, so these names are all invalid.
     *
     * @return void
     */
    public function testInvalidClassFormatPrivate()
    {
        $this->assertFalse(Common::isCamelCaps('_ThisIsCamelCaps', true, true));
        $this->assertFalse(Common::isCamelCaps('_ThisIsCamelCaps', true, false));

    }//end testInvalidClassFormatPrivate()


}//end class