How to use AtMost class

Best Mockery code snippet using .AtMost

Run Mockery automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

AtMostTest.php

Source: AtMostTest.php Github

copy
1<?php
2
3/*
4 * This file is part of the webmozart/expression package.
5 *
6 * (c) Bernhard Schussek <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Webmozart\Expression\Tests\Selector;
13
14use ArrayIterator;
15use PHPUnit_Framework_TestCase;
16use Webmozart\Expression\Constraint\EndsWith;
17use Webmozart\Expression\Constraint\GreaterThan;
18use Webmozart\Expression\Logic\AndX;
19use Webmozart\Expression\Selector\AtMost;
20
21/**
22 * @since  1.0
23 *
24 * @author Bernhard Schussek <bschussek@gmail.com>
25 */
26class AtMostTest extends PHPUnit_Framework_TestCase
27{
28    public function testEvaluate()
29    {
30        $atMost1 = new AtMost(1, new GreaterThan(10));
31        $atMost2 = new AtMost(2, new GreaterThan(10));
32
33        $this->assertFalse($atMost1->evaluate(array(9, 10, 11, 12)));
34        $this->assertTrue($atMost1->evaluate(array(9, 10, 11)));
35        $this->assertTrue($atMost1->evaluate(array(9, 10)));
36        $this->assertFalse($atMost1->evaluate(new ArrayIterator(array(9, 10, 11, 12))));
37        $this->assertTrue($atMost1->evaluate(new ArrayIterator(array(9, 10, 11))));
38        $this->assertTrue($atMost1->evaluate(new ArrayIterator(array(9, 10))));
39
40        $this->assertFalse($atMost2->evaluate(array(9, 10, 11, 12, 13)));
41        $this->assertTrue($atMost2->evaluate(array(9, 10, 11, 12)));
42        $this->assertTrue($atMost2->evaluate(array(9, 10, 11)));
43        $this->assertTrue($atMost2->evaluate(array(9, 10)));
44        $this->assertFalse($atMost2->evaluate(new ArrayIterator(array(9, 10, 11, 12, 13))));
45        $this->assertTrue($atMost2->evaluate(new ArrayIterator(array(9, 10, 11, 12))));
46        $this->assertTrue($atMost2->evaluate(new ArrayIterator(array(9, 10, 11))));
47        $this->assertTrue($atMost2->evaluate(new ArrayIterator(array(9, 10))));
48
49        $this->assertTrue($atMost1->evaluate(array()));
50        $this->assertFalse($atMost1->evaluate('foobar'));
51    }
52
53    public function testToString()
54    {
55        $expr1 = new AtMost(1, new GreaterThan(10));
56        $expr2 = new AtMost(2, new EndsWith('.css'));
57        $expr3 = new AtMost(3, new AndX(array(
58            new GreaterThan(10),
59            new EndsWith('.css'),
60        )));
61
62        $this->assertSame('atMost(1, >10)', $expr1->toString());
63        $this->assertSame('atMost(2, endsWith(".css"))', $expr2->toString());
64        $this->assertSame('atMost(3, >10 && endsWith(".css"))', $expr3->toString());
65    }
66}
67
Full Screen

displayUpgradePopin.php

Source: displayUpgradePopin.php Github

copy
1<?php
2
3namespace WP_Rocket\Tests\Unit\inc\Engine\License\Upgrade;
4
5use Brain\Monkey\Functions;
6use Mockery;
7use WP_Rocket\Engine\License\API\Pricing;
8use WP_Rocket\Engine\License\API\User;
9use WP_Rocket\Engine\License\Upgrade;
10use WP_Rocket\Tests\Unit\TestCase;
11
12/**
13 * @covers \WP_Rocket\Engine\License\Upgrade::display_upgrade_popin
14 *
15 * @group License
16 */
17class DisplayUpgradePopin extends TestCase {
18	private $pricing;
19	private $user;
20	private $upgrade;
21
22	public function setUp() : void {
23		parent::setUp();
24
25		Functions\stubTranslationFunctions();
26
27		$this->pricing = Mockery::mock( Pricing::class );
28		$this->user    = Mockery::mock( User::class );
29		$this->upgrade = Mockery::mock(
30			Upgrade::class . '[generate]',
31			[
32				$this->pricing,
33				$this->user,
34				'views',
35			]
36		);
37	}
38
39	/**
40	 * @dataProvider configTestData
41	 */
42	public function testShouldReturnExpected( $config, $expected ) {
43		$this->user->shouldReceive( 'get_license_type' )
44			->atMost()
45			->twice()
46			->andReturn( $config['license_account'] );
47
48		$this->user->shouldReceive( 'is_license_expired' )
49			->atMost()
50			->once()
51			->andReturn( $config['licence_expiration'] );
52
53		if ( ! is_null( $expected ) ) {
54			$this->pricing->shouldReceive( 'get_single_websites_count' )
55				->atMost()
56				->once()
57				->andReturn( $config['pricing']['single']['websites'] );
58
59			$this->pricing->shouldReceive( 'get_plus_websites_count' )
60				->atMost()
61				->twice()
62				->andReturn( $config['pricing']['plus']['websites'] );
63
64			$this->pricing->shouldReceive( 'get_single_to_plus_price' )
65				->atMost()
66				->once()
67				->andReturn( $config['pricing']['plus']['price'] );
68			
69			$this->pricing->shouldReceive( 'get_regular_single_to_plus_price' )
70				->atMost()
71				->once()
72				->andReturn( $config['pricing']['plus']['regular'] );
73
74			$this->user->shouldReceive( 'get_upgrade_plus_url' )
75				->atMost()
76				->once()
77				->andReturn( $config['pricing']['plus']['upgrade_url'] );
78
79			$this->pricing->shouldReceive( 'get_single_to_infinite_price' )
80				->atMost()
81				->once()
82				->andReturn( $config['pricing']['infinite']['price'] );
83		
84			$this->pricing->shouldReceive( 'get_regular_single_to_infinite_price' )
85				->atMost()
86				->once()
87				->andReturn( $config['pricing']['infinite']['regular'] );
88
89			$this->pricing->shouldReceive( 'get_infinite_websites_count' )
90				->atMost()
91				->once()
92				->andReturn( $config['pricing']['infinite']['websites'] );
93
94			$this->user->shouldReceive( 'get_upgrade_infinite_url' )
95				->atMost()
96				->once()
97				->andReturn( $config['pricing']['infinite']['upgrade_url'] );
98
99			$this->pricing->shouldReceive( 'get_plus_to_infinite_price' )
100				->atMost()
101				->once()
102				->andReturn( $config['pricing']['infinite']['price'] );
103
104			$this->pricing->shouldReceive( 'get_regular_plus_to_infinite_price' )
105				->atMost()
106				->once()
107				->andReturn( $config['pricing']['infinite']['regular'] );
108
109			$this->pricing->shouldReceive( 'is_promo_active' )
110				->andReturn( $config['promo_active'] );
111
112			$this->upgrade->shouldReceive( 'generate' )
113				->once()
114				->with(
115					'upgrade-popin',
116					$expected
117				)
118				->andReturn( '' );
119			$this->expectOutputString( '' );
120		} else {
121			$this->upgrade->shouldReceive( 'generate' )
122				->never();
123		}
124
125		$this->upgrade->display_upgrade_popin();
126	}
127}
128
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used methods in AtMost

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)