How to use Kernel class

Best AspectMock code snippet using Kernel

KernelTest.php

Source:KernelTest.php Github

copy

Full Screen

...6 *7 * For the full copyright and license information, please view the LICENSE8 * file that was distributed with this source code.9 */10namespace Symfony\Component\HttpKernel\Tests;11use PHPUnit\Framework\TestCase;12use Symfony\Component\Config\Loader\LoaderInterface;13use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;14use Symfony\Component\DependencyInjection\ContainerBuilder;15use Symfony\Component\Filesystem\Filesystem;16use Symfony\Component\HttpFoundation\Request;17use Symfony\Component\HttpFoundation\Response;18use Symfony\Component\HttpKernel\Bundle\BundleInterface;19use Symfony\Component\HttpKernel\DependencyInjection\ResettableServicePass;20use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;21use Symfony\Component\HttpKernel\HttpKernelInterface;22use Symfony\Component\HttpKernel\Kernel;23use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForOverrideName;24use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest;25use Symfony\Component\HttpKernel\Tests\Fixtures\KernelWithoutBundles;26use Symfony\Component\HttpKernel\Tests\Fixtures\ResettableService;27class KernelTest extends TestCase28{29 public static function tearDownAfterClass()30 {31 $fs = new Filesystem();32 $fs->remove(__DIR__.'/Fixtures/var');33 }34 public function testConstructor()35 {36 $env = 'test_env';37 $debug = true;38 $kernel = new KernelForTest($env, $debug);39 $this->assertEquals($env, $kernel->getEnvironment());40 $this->assertEquals($debug, $kernel->isDebug());41 $this->assertFalse($kernel->isBooted());42 $this->assertLessThanOrEqual(microtime(true), $kernel->getStartTime());43 $this->assertNull($kernel->getContainer());44 }45 public function testClone()46 {47 $env = 'test_env';48 $debug = true;49 $kernel = new KernelForTest($env, $debug);50 $clone = clone $kernel;51 $this->assertEquals($env, $clone->getEnvironment());52 $this->assertEquals($debug, $clone->isDebug());53 $this->assertFalse($clone->isBooted());54 $this->assertLessThanOrEqual(microtime(true), $clone->getStartTime());55 $this->assertNull($clone->getContainer());56 }57 /**58 * @expectedException \InvalidArgumentException59 * @expectedExceptionMessage The environment "test.env" contains invalid characters, it can only contain characters allowed in PHP class names.60 */61 public function testClassNameValidityGetter()62 {63 // We check the classname that will be generated by using a $env that64 // contains invalid characters.65 $env = 'test.env';66 $kernel = new KernelForTest($env, false);67 $kernel->boot();68 }69 public function testInitializeContainerClearsOldContainers()70 {71 $fs = new Filesystem();72 $legacyContainerDir = __DIR__.'/Fixtures/var/cache/custom/ContainerA123456';73 $fs->mkdir($legacyContainerDir);74 touch($legacyContainerDir.'.legacy');75 $kernel = new CustomProjectDirKernel();76 $kernel->boot();77 $containerDir = __DIR__.'/Fixtures/var/cache/custom/'.substr(\get_class($kernel->getContainer()), 0, 16);78 $this->assertTrue(unlink(__DIR__.'/Fixtures/var/cache/custom/TestsSymfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta'));79 $this->assertFileExists($containerDir);80 $this->assertFileNotExists($containerDir.'.legacy');81 $kernel = new CustomProjectDirKernel(function ($container) { $container->register('foo', 'stdClass')->setPublic(true); });82 $kernel->boot();83 $this->assertFileExists($containerDir);84 $this->assertFileExists($containerDir.'.legacy');85 $this->assertFileNotExists($legacyContainerDir);86 $this->assertFileNotExists($legacyContainerDir.'.legacy');87 }88 public function testBootInitializesBundlesAndContainer()89 {90 $kernel = $this->getKernel(['initializeBundles', 'initializeContainer']);91 $kernel->expects($this->once())92 ->method('initializeBundles');93 $kernel->expects($this->once())94 ->method('initializeContainer');95 $kernel->boot();96 }97 public function testBootSetsTheContainerToTheBundles()98 {99 $bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')->getMock();100 $bundle->expects($this->once())101 ->method('setContainer');102 $kernel = $this->getKernel(['initializeBundles', 'initializeContainer', 'getBundles']);103 $kernel->expects($this->once())104 ->method('getBundles')105 ->willReturn([$bundle]);106 $kernel->boot();107 }108 public function testBootSetsTheBootedFlagToTrue()109 {110 // use test kernel to access isBooted()111 $kernel = $this->getKernelForTest(['initializeBundles', 'initializeContainer']);112 $kernel->boot();113 $this->assertTrue($kernel->isBooted());114 }115 public function testClassCacheIsNotLoadedByDefault()116 {117 $kernel = $this->getKernel(['initializeBundles', 'initializeContainer', 'doLoadClassCache']);118 $kernel->expects($this->never())119 ->method('doLoadClassCache');120 $kernel->boot();121 }122 public function testBootKernelSeveralTimesOnlyInitializesBundlesOnce()123 {124 $kernel = $this->getKernel(['initializeBundles', 'initializeContainer']);125 $kernel->expects($this->once())126 ->method('initializeBundles');127 $kernel->boot();128 $kernel->boot();129 }130 public function testShutdownCallsShutdownOnAllBundles()131 {132 $bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')->getMock();133 $bundle->expects($this->once())134 ->method('shutdown');135 $kernel = $this->getKernel([], [$bundle]);136 $kernel->boot();137 $kernel->shutdown();138 }139 public function testShutdownGivesNullContainerToAllBundles()140 {141 $bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')->getMock();142 $bundle->expects($this->at(3))143 ->method('setContainer')144 ->with(null);145 $kernel = $this->getKernel(['getBundles']);146 $kernel->expects($this->any())147 ->method('getBundles')148 ->willReturn([$bundle]);149 $kernel->boot();150 $kernel->shutdown();151 }152 public function testHandleCallsHandleOnHttpKernel()153 {154 $type = HttpKernelInterface::MASTER_REQUEST;155 $catch = true;156 $request = new Request();157 $httpKernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernel')158 ->disableOriginalConstructor()159 ->getMock();160 $httpKernelMock161 ->expects($this->once())162 ->method('handle')163 ->with($request, $type, $catch);164 $kernel = $this->getKernel(['getHttpKernel']);165 $kernel->expects($this->once())166 ->method('getHttpKernel')167 ->willReturn($httpKernelMock);168 $kernel->handle($request, $type, $catch);169 }170 public function testHandleBootsTheKernel()171 {172 $type = HttpKernelInterface::MASTER_REQUEST;173 $catch = true;174 $request = new Request();175 $httpKernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernel')176 ->disableOriginalConstructor()177 ->getMock();178 $kernel = $this->getKernel(['getHttpKernel', 'boot']);179 $kernel->expects($this->once())180 ->method('getHttpKernel')181 ->willReturn($httpKernelMock);182 $kernel->expects($this->once())183 ->method('boot');184 $kernel->handle($request, $type, $catch);185 }186 public function testStripComments()187 {188 $source = <<<'EOF'189<?php190$string = 'string should not be modified';191$string = 'string should not be192modified';193$heredoc = <<<HD194Heredoc should not be modified {$a[1+$b]}195HD;196$nowdoc = <<<'ND'197Nowdoc should not be modified198ND;199/**200 * some class comments to strip201 */202class TestClass203{204 /**205 * some method comments to strip206 */207 public function doStuff()208 {209 // inline comment210 }211}212EOF;213 $expected = <<<'EOF'214<?php215$string = 'string should not be modified';216$string = 'string should not be217modified';218$heredoc = <<<HD219Heredoc should not be modified {$a[1+$b]}220HD;221$nowdoc = <<<'ND'222Nowdoc should not be modified223ND;224class TestClass225{226 public function doStuff()227 {228 }229}230EOF;231 $output = Kernel::stripComments($source);232 // Heredocs are preserved, making the output mixing Unix and Windows line233 // endings, switching to "\n" everywhere on Windows to avoid failure.234 if ('\\' === \DIRECTORY_SEPARATOR) {235 $expected = str_replace("\r\n", "\n", $expected);236 $output = str_replace("\r\n", "\n", $output);237 }238 $this->assertEquals($expected, $output);239 }240 /**241 * @group legacy242 */243 public function testGetRootDir()244 {245 $kernel = new KernelForTest('test', true);246 $this->assertEquals(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures', realpath($kernel->getRootDir()));247 }248 /**249 * @group legacy250 */251 public function testGetName()252 {253 $kernel = new KernelForTest('test', true);254 $this->assertEquals('Fixtures', $kernel->getName());255 }256 /**257 * @group legacy258 */259 public function testOverrideGetName()260 {261 $kernel = new KernelForOverrideName('test', true);262 $this->assertEquals('overridden', $kernel->getName());263 }264 public function testSerialize()265 {266 $env = 'test_env';267 $debug = true;268 $kernel = new KernelForTest($env, $debug);269 $expected = "O:57:\"Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest\":2:{s:14:\"\0*\0environment\";s:8:\"test_env\";s:8:\"\0*\0debug\";b:1;}";270 $this->assertEquals($expected, serialize($kernel));271 }272 /**273 * @expectedException \InvalidArgumentException274 */275 public function testLocateResourceThrowsExceptionWhenNameIsNotValid()276 {277 $this->getKernel()->locateResource('Foo');278 }279 /**280 * @expectedException \RuntimeException281 */282 public function testLocateResourceThrowsExceptionWhenNameIsUnsafe()283 {284 $this->getKernel()->locateResource('@FooBundle/../bar');285 }286 /**287 * @expectedException \InvalidArgumentException288 */289 public function testLocateResourceThrowsExceptionWhenBundleDoesNotExist()290 {291 $this->getKernel()->locateResource('@FooBundle/config/routing.xml');292 }293 /**294 * @expectedException \InvalidArgumentException295 */296 public function testLocateResourceThrowsExceptionWhenResourceDoesNotExist()297 {298 $kernel = $this->getKernel(['getBundle']);299 $kernel300 ->expects($this->once())301 ->method('getBundle')302 ->willReturn($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle'))303 ;304 $kernel->locateResource('@Bundle1Bundle/config/routing.xml');305 }306 public function testLocateResourceReturnsTheFirstThatMatches()307 {308 $kernel = $this->getKernel(['getBundle']);309 $kernel310 ->expects($this->once())311 ->method('getBundle')312 ->willReturn($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle'))313 ;314 $this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/foo.txt', $kernel->locateResource('@Bundle1Bundle/foo.txt'));315 }316 public function testLocateResourceIgnoresDirOnNonResource()317 {318 $kernel = $this->getKernel(['getBundle']);319 $kernel320 ->expects($this->once())321 ->method('getBundle')322 ->willReturn($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle'))323 ;324 $this->assertEquals(325 __DIR__.'/Fixtures/Bundle1Bundle/foo.txt',326 $kernel->locateResource('@Bundle1Bundle/foo.txt', __DIR__.'/Fixtures')327 );328 }329 public function testLocateResourceReturnsTheDirOneForResources()330 {331 $kernel = $this->getKernel(['getBundle']);332 $kernel333 ->expects($this->once())334 ->method('getBundle')335 ->willReturn($this->getBundle(__DIR__.'/Fixtures/FooBundle', null, null, 'FooBundle'))336 ;337 $this->assertEquals(338 __DIR__.'/Fixtures/Resources/FooBundle/foo.txt',339 $kernel->locateResource('@FooBundle/Resources/foo.txt', __DIR__.'/Fixtures/Resources')340 );341 }342 public function testLocateResourceOnDirectories()343 {344 $kernel = $this->getKernel(['getBundle']);345 $kernel346 ->expects($this->exactly(2))347 ->method('getBundle')348 ->willReturn($this->getBundle(__DIR__.'/Fixtures/FooBundle', null, null, 'FooBundle'))349 ;350 $this->assertEquals(351 __DIR__.'/Fixtures/Resources/FooBundle/',352 $kernel->locateResource('@FooBundle/Resources/', __DIR__.'/Fixtures/Resources')353 );354 $this->assertEquals(355 __DIR__.'/Fixtures/Resources/FooBundle',356 $kernel->locateResource('@FooBundle/Resources', __DIR__.'/Fixtures/Resources')357 );358 $kernel = $this->getKernel(['getBundle']);359 $kernel360 ->expects($this->exactly(2))361 ->method('getBundle')362 ->willReturn($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle', null, null, 'Bundle1Bundle'))363 ;364 $this->assertEquals(365 __DIR__.'/Fixtures/Bundle1Bundle/Resources/',366 $kernel->locateResource('@Bundle1Bundle/Resources/')367 );368 $this->assertEquals(369 __DIR__.'/Fixtures/Bundle1Bundle/Resources',370 $kernel->locateResource('@Bundle1Bundle/Resources')371 );372 }373 /**374 * @expectedException \LogicException375 * @expectedExceptionMessage Trying to register two bundles with the same name "DuplicateName"376 */377 public function testInitializeBundleThrowsExceptionWhenRegisteringTwoBundlesWithTheSameName()378 {379 $fooBundle = $this->getBundle(null, null, 'FooBundle', 'DuplicateName');380 $barBundle = $this->getBundle(null, null, 'BarBundle', 'DuplicateName');381 $kernel = $this->getKernel([], [$fooBundle, $barBundle]);382 $kernel->boot();383 }384 public function testTerminateReturnsSilentlyIfKernelIsNotBooted()385 {386 $kernel = $this->getKernel(['getHttpKernel']);387 $kernel->expects($this->never())388 ->method('getHttpKernel');389 $kernel->terminate(Request::create('/'), new Response());390 }391 public function testTerminateDelegatesTerminationOnlyForTerminableInterface()392 {393 // does not implement TerminableInterface394 $httpKernel = new TestKernel();395 $kernel = $this->getKernel(['getHttpKernel']);396 $kernel->expects($this->once())397 ->method('getHttpKernel')398 ->willReturn($httpKernel);399 $kernel->boot();400 $kernel->terminate(Request::create('/'), new Response());401 $this->assertFalse($httpKernel->terminateCalled, 'terminate() is never called if the kernel class does not implement TerminableInterface');402 // implements TerminableInterface403 $httpKernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernel')404 ->disableOriginalConstructor()405 ->setMethods(['terminate'])406 ->getMock();407 $httpKernelMock408 ->expects($this->once())409 ->method('terminate');410 $kernel = $this->getKernel(['getHttpKernel']);411 $kernel->expects($this->exactly(2))412 ->method('getHttpKernel')413 ->willReturn($httpKernelMock);414 $kernel->boot();415 $kernel->terminate(Request::create('/'), new Response());416 }417 public function testKernelWithoutBundles()418 {419 $kernel = new KernelWithoutBundles('test', true);420 $kernel->boot();421 $this->assertTrue($kernel->getContainer()->getParameter('test_executed'));422 }423 public function testProjectDirExtension()424 {425 $kernel = new CustomProjectDirKernel();426 $kernel->boot();427 $this->assertSame(__DIR__.'/Fixtures', $kernel->getProjectDir());428 $this->assertSame(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures', $kernel->getContainer()->getParameter('kernel.project_dir'));429 }430 public function testKernelReset()431 {432 (new Filesystem())->remove(__DIR__.'/Fixtures/var/cache');433 $kernel = new CustomProjectDirKernel();434 $kernel->boot();435 $containerClass = \get_class($kernel->getContainer());436 $containerFile = (new \ReflectionClass($kernel->getContainer()))->getFileName();437 unlink(__DIR__.'/Fixtures/var/cache/custom/TestsSymfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta');438 $kernel = new CustomProjectDirKernel();439 $kernel->boot();440 $this->assertInstanceOf($containerClass, $kernel->getContainer());441 $this->assertFileExists($containerFile);442 unlink(__DIR__.'/Fixtures/var/cache/custom/TestsSymfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta');443 $kernel = new CustomProjectDirKernel(function ($container) { $container->register('foo', 'stdClass')->setPublic(true); });444 $kernel->boot();445 $this->assertNotInstanceOf($containerClass, $kernel->getContainer());446 $this->assertFileExists($containerFile);447 $this->assertFileExists(\dirname($containerFile).'.legacy');448 }449 public function testKernelPass()450 {451 $kernel = new PassKernel();452 $kernel->boot();453 $this->assertTrue($kernel->getContainer()->getParameter('test.processed'));454 }455 public function testServicesResetter()456 {457 $httpKernelMock = $this->getMockBuilder(HttpKernelInterface::class)458 ->disableOriginalConstructor()459 ->getMock();460 $httpKernelMock461 ->expects($this->exactly(2))462 ->method('handle');463 $kernel = new CustomProjectDirKernel(function ($container) {464 $container->addCompilerPass(new ResettableServicePass());465 $container->register('one', ResettableService::class)466 ->setPublic(true)467 ->addTag('kernel.reset', ['method' => 'reset']);468 $container->register('services_resetter', ServicesResetter::class)->setPublic(true);469 }, $httpKernelMock, 'resetting');470 ResettableService::$counter = 0;471 $request = new Request();472 $kernel->handle($request);473 $kernel->getContainer()->get('one');474 $this->assertEquals(0, ResettableService::$counter);475 $this->assertFalse($kernel->getContainer()->initialized('services_resetter'));476 $kernel->handle($request);477 $this->assertEquals(1, ResettableService::$counter);478 }479 /**480 * @group time-sensitive481 */482 public function testKernelStartTimeIsResetWhileBootingAlreadyBootedKernel()483 {484 $kernel = $this->getKernelForTest(['initializeBundles'], true);485 $kernel->boot();486 $preReBoot = $kernel->getStartTime();487 sleep(3600); //Intentionally large value to detect if ClockMock ever breaks488 $kernel->reboot(null);489 $this->assertGreaterThan($preReBoot, $kernel->getStartTime());490 }491 /**492 * Returns a mock for the BundleInterface.493 *494 * @return BundleInterface495 */496 protected function getBundle($dir = null, $parent = null, $className = null, $bundleName = null)497 {498 $bundle = $this499 ->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface')500 ->setMethods(['getPath', 'getParent', 'getName'])501 ->disableOriginalConstructor()502 ;503 if ($className) {504 $bundle->setMockClassName($className);505 }506 $bundle = $bundle->getMockForAbstractClass();507 $bundle508 ->expects($this->any())509 ->method('getName')510 ->willReturn(null === $bundleName ? \get_class($bundle) : $bundleName)511 ;512 $bundle513 ->expects($this->any())514 ->method('getPath')515 ->willReturn($dir)516 ;517 $bundle518 ->expects($this->any())519 ->method('getParent')520 ->willReturn($parent)521 ;522 return $bundle;523 }524 /**525 * Returns a mock for the abstract kernel.526 *527 * @param array $methods Additional methods to mock (besides the abstract ones)528 * @param array $bundles Bundles to register529 *530 * @return Kernel531 */532 protected function getKernel(array $methods = [], array $bundles = [])533 {534 $methods[] = 'registerBundles';535 $kernel = $this536 ->getMockBuilder('Symfony\Component\HttpKernel\Kernel')537 ->setMethods($methods)538 ->setConstructorArgs(['test', false])539 ->getMockForAbstractClass()540 ;541 $kernel->expects($this->any())542 ->method('registerBundles')543 ->willReturn($bundles)544 ;545 $p = new \ReflectionProperty($kernel, 'rootDir');546 $p->setAccessible(true);547 $p->setValue($kernel, __DIR__.'/Fixtures');548 return $kernel;549 }550 protected function getKernelForTest(array $methods = [], $debug = false)551 {552 $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')553 ->setConstructorArgs(['test', $debug])554 ->setMethods($methods)555 ->getMock();556 $p = new \ReflectionProperty($kernel, 'rootDir');557 $p->setAccessible(true);558 $p->setValue($kernel, __DIR__.'/Fixtures');559 return $kernel;560 }561}562class TestKernel implements HttpKernelInterface563{564 public $terminateCalled = false;565 public function terminate()566 {567 $this->terminateCalled = true;568 }569 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)570 {571 }572}573class CustomProjectDirKernel extends Kernel574{575 private $baseDir;576 private $buildContainer;577 private $httpKernel;578 public function __construct(\Closure $buildContainer = null, HttpKernelInterface $httpKernel = null, $env = 'custom')579 {580 parent::__construct($env, true);581 $this->buildContainer = $buildContainer;582 $this->httpKernel = $httpKernel;583 }584 public function registerBundles()585 {586 return [];587 }588 public function registerContainerConfiguration(LoaderInterface $loader)589 {590 }591 public function getProjectDir()592 {593 return __DIR__.'/Fixtures';594 }595 protected function build(ContainerBuilder $container)596 {597 if ($build = $this->buildContainer) {598 $build($container);599 }600 }601 protected function getHttpKernel()602 {603 return $this->httpKernel;604 }605}606class PassKernel extends CustomProjectDirKernel implements CompilerPassInterface607{608 public function __construct()609 {610 parent::__construct();611 Kernel::__construct('pass', true);612 }613 public function process(ContainerBuilder $container)614 {615 $container->setParameter('test.processed', true);616 }617}...

Full Screen

Full Screen

kernel.rb

Source:kernel.rb Github

copy

Full Screen

...20# implied.21# See the License for the specific language governing permissions and22# limitations under the License.23#24Ohai.plugin(:Kernel) do25 provides "kernel", "kernel/modules"26 # common initial kernel attribute values27 def init_kernel28 kernel Mash.new29 [["uname -s", :name], ["uname -r", :release],30 ["uname -v", :version], ["uname -m", :machine],31 ["uname -p", :processor]].each do |cmd, property|32 so = shell_out(cmd)33 kernel[property] = so.stdout.split($/)[0]34 end35 kernel36 end37 # common *bsd code for collecting modules data38 def bsd_modules(path)...

Full Screen

Full Screen

grub_conf.rb

Source:grub_conf.rb Github

copy

Full Screen

1# encoding: utf-82# author: Thomas Cate3# license: All rights reserved4require 'utils/simpleconfig'5class GrubConfig < Inspec.resource(1) # rubocop:disable Metrics/ClassLength6 name 'grub_conf'7 desc 'Use the grub_conf InSpec audit resource to test the boot config of Linux systems that use Grub.'8 example "9 describe grub_conf('/etc/grub.conf', 'default') do10 its('kernel') { should include '/vmlinuz-2.6.32-573.7.1.el6.x86_64' }11 its('initrd') { should include '/initramfs-2.6.32-573.el6.x86_64.img=1' }12 its('default') { should_not eq '1' }13 its('timeout') { should eq '5' }14 end15 also check specific kernels16 describe grub_conf('/etc/grub.conf', 'CentOS (2.6.32-573.12.1.el6.x86_64)') do17 its('kernel') { should include 'audit=1' }18 end19 "20 def initialize(path = nil, kernel = nil)21 family = inspec.os[:family]22 case family23 when 'redhat', 'fedora', 'centos'24 release = inspec.os[:release].to_f25 supported = true26 if release < 727 @conf_path = path || '/etc/grub.conf'28 @version = 'legacy'29 else30 @conf_path = path || '/boot/grub/grub.cfg'31 @defaults_path = '/etc/default/grub'32 @version = 'grub2'33 end34 when 'ubuntu'35 @conf_path = path || '/boot/grub/grub.cfg'36 @defaults_path = '/etc/default/grub'37 @version = 'grub2'38 supported = true39 end40 @kernel = kernel || 'default'41 return skip_resource 'The `grub_config` resource is not supported on your OS yet.' if supported.nil?42 end43 def method_missing(name)44 read_params[name.to_s]45 end46 def to_s47 'Grub Config'48 end49 private50 ######################################################################51 # Grub2 This is used by all supported versions of Ubuntu and Rhel 7+ #52 ######################################################################53 def grub2_parse_kernel_lines(content, conf)54 # Find all "menuentry" lines and then parse them into arrays55 menu_entry = 056 lines = content.split("\n")57 kernel_opts = {}58 kernel_opts['insmod'] = []59 lines.each_with_index do |file_line, index|60 next unless file_line =~ /(^|\s)menuentry\s.*/61 lines.drop(index+1).each do |kernel_line|62 next if kernel_line =~ /(^|\s)(menu|}).*/63 if menu_entry == conf['GRUB_DEFAULT'].to_i && @kernel == 'default'64 if kernel_line =~ /(^|\s)initrd.*/65 kernel_opts['initrd'] = kernel_line.split(' ')[1]66 end67 if kernel_line =~ /(^|\s)linux.*/68 kernel_opts['kernel'] = kernel_line.split69 end70 if kernel_line =~ /(^|\s)set root=.*/71 kernel_opts['root'] = kernel_line.split('=')[1].tr('\'', '')72 end73 if kernel_line =~ /(^|\s)insmod.*/74 kernel_opts['insmod'].push(kernel_line.split(' ')[1])75 end76 else77 menu_entry += 178 break79 end80 end81 end82 kernel_opts83 end84 ###################################################################85 # Grub1 aka legacy-grub config. Primarily used by Centos/Rhel 6.x #86 ###################################################################87 def parse_kernel_lines(content, conf)88 # Find all "title" lines and then parse them into arrays89 menu_entry = 090 lines = content.split("\n")91 kernel_opts = {}92 lines.each_with_index do |file_line, index|93 next unless file_line =~ /^title.*/94 current_kernel = file_line.split(' ', 2)[1]95 lines.drop(index+1).each do |kernel_line|96 if kernel_line =~ /^\s.*/97 option_type = kernel_line.split(' ')[0]98 line_options = kernel_line.split(' ').drop(1)99 if (menu_entry == conf['default'].to_i && @kernel == 'default') || current_kernel == @kernel100 if option_type == 'kernel'101 kernel_opts['kernel'] = line_options102 else103 kernel_opts[option_type] = line_options[0]104 end105 end106 else107 menu_entry += 1108 break109 end110 end111 end112 kernel_opts113 end114 def read_file(config_file)115 file = inspec.file(config_file)116 if !file.file? && !file.symlink?117 skip_resource "Can't find file '#{@conf_path}'"118 return @params = {}119 end120 content = file.content121 if content.empty? && file.size > 0122 skip_resource "Can't read file '#{@conf_path}'"123 return @params = {}124 end125 content126 end127 def read_params128 return @params if defined?(@params)129 content = read_file(@conf_path)130 if @version == 'legacy'131 # parse the file132 conf = SimpleConfig.new(133 content,134 multiple_values: true,135 ).params136 # convert single entry arrays into strings137 conf.each do |key, value|138 if value.size == 1139 conf[key] = conf[key][0].to_s140 end141 end142 kernel_opts = parse_kernel_lines(content, conf)143 @params = conf.merge(kernel_opts)144 end145 if @version == 'grub2'146 # read defaults147 defaults = read_file(@defaults_path)148 conf = SimpleConfig.new(149 defaults,150 multiple_values: true,151 ).params152 # convert single entry arrays into strings153 conf.each do |key, value|154 if value.size == 1155 conf[key] = conf[key][0].to_s156 end157 end158 kernel_opts = grub2_parse_kernel_lines(content, conf)159 @params = conf.merge(kernel_opts)160 end161 @params162 end163end...

Full Screen

Full Screen

send.rb

Source:send.rb Github

copy

Full Screen

1describe :kernel_send, :shared => true do2 it "invokes the named method" do3 class KernelSpecs::Foo4 def bar5 'done'6 end7 end8 KernelSpecs::Foo.new.send(@method, :bar).should == 'done'9 KernelSpecs::Foo.new.send(@method, "bar").should == 'done'10 end11 12 it "invokes the named public method" do13 class KernelSpecs::Foo14 def bar15 'done'16 end17 end18 KernelSpecs::Foo.new.send(@method, :bar).should == 'done'19 end20 it "invokes the named alias of a public method" do21 class KernelSpecs::Foo22 alias :aka :bar23 def bar24 'done'25 end26 end27 KernelSpecs::Foo.new.send(@method, :aka).should == 'done'28 end29 it "invokes the named protected method" do30 class KernelSpecs::Foo31 protected32 def bar33 'done'34 end35 end36 KernelSpecs::Foo.new.send(@method, :bar).should == 'done'37 end38 it "invokes the named private method" do39 class KernelSpecs::Foo40 private41 def bar42 'done2'43 end44 end45 KernelSpecs::Foo.new.send(@method, :bar).should == 'done2'46 end47 it "invokes the named alias of a private method" do48 class KernelSpecs::Foo49 alias :aka :bar50 private51 def bar52 'done2'53 end54 end55 KernelSpecs::Foo.new.send(@method, :aka).should == 'done2'56 end57 it "invokes the named alias of a protected method" do58 class KernelSpecs::Foo59 alias :aka :bar60 protected61 def bar62 'done2'63 end64 end65 KernelSpecs::Foo.new.send(@method, :aka).should == 'done2'66 end67 it "invokes a class method if called on a class" do68 class KernelSpecs::Foo69 def self.bar70 'done'71 end72 end73 KernelSpecs::Foo.send(@method, :bar).should == 'done'74 end75 it "raises a NameError if the corresponding method can't be found" do76 class KernelSpecs::Foo77 def bar78 'done'79 end80 end81 lambda { KernelSpecs::Foo.new.send(@method, :syegsywhwua) }.should raise_error(NameError)82 end83 it "raises a TypeError if the first argument isn't a Symbol or string" do84 lambda {KernelSpecs::Foo.new.send(@method, [])}.should raise_error(TypeError)85 end86 it "raises a NameError if the corresponding singleton method can't be found" do87 class KernelSpecs::Foo88 def self.bar89 'done'90 end91 end92 lambda { KernelSpecs::Foo.send(@method, :baz) }.should raise_error(NameError)93 end94 it "raises an ArgumentError if no arguments are given" do95 lambda { KernelSpecs::Foo.new.send }.should raise_error(ArgumentError)96 end97 it "raises an ArgumentError if called with more arguments than available parameters" do98 class KernelSpecs::Foo99 def bar; end100 end101 lambda { KernelSpecs::Foo.new.send(:bar, :arg) }.should raise_error(ArgumentError)102 end103 it "raises an ArgumentError if called with fewer arguments than required parameters" do104 class KernelSpecs::Foo105 def foo(arg); end106 end107 lambda { KernelSpecs::Foo.new.send(@method, :foo) }.should raise_error(ArgumentError)108 end109 it "succeeds if passed an arbitrary number of arguments as a splat parameter" do110 class KernelSpecs::Foo111 def baz(*args) args end112 end113 begin114 KernelSpecs::Foo.new.send(@method, :baz).should == []115 KernelSpecs::Foo.new.send(@method, :baz, :quux).should == [:quux]116 KernelSpecs::Foo.new.send(@method, :baz, :quux, :foo).should == [:quux, :foo]117 rescue118 fail119 end120 end121 it "succeeds when passing 1 or more arguments as a required and a splat parameter" do122 class KernelSpecs::Foo123 def foo(first, *rest) [first, *rest] end124 end125 begin126 KernelSpecs::Foo.new.send(@method, :baz, :quux).should == [:quux]127 KernelSpecs::Foo.new.send(@method, :baz, :quux, :foo).should == [:quux, :foo]128 rescue129 fail130 end131 end132 it "succeeds when passing 0 arguments to a method with one parameter with a default" do133 class KernelSpecs::Foo134 def foo(first = true) first end135 end136 begin137 KernelSpecs::Foo.new.send(@method, :foo).should == true138 KernelSpecs::Foo.new.send(@method, :foo, :arg).should == :arg139 rescue140 fail141 end142 end143 it "passes the block into the method" do144 class KernelSpecs::Foo145 def iter146 a = []147 yield a148 a149 end150 end151 KernelSpecs::Foo.new.send(@method, :iter) { |b| b << 1}.should == [1]152 end153 not_compliant_on :rubinius do154 # Confirm commit r24306155 it "has an arity of -1" do156 method(:__send__).arity.should == -1157 end158 end159 deviates_on :rubinius do160 it "has an arity of -2" do161 method(:__send__).arity.should == -2162 end163 end164end...

Full Screen

Full Screen

Kernel

Using AI Code Generation

copy

Full Screen

1$kernel = AspectMock\Kernel::getInstance();2$kernel->init([3]);4$kernel->loadFile(__DIR__ . '/../../src/Class.php');5$class = new Class();6$class->method();

Full Screen

Full Screen

Kernel

Using AI Code Generation

copy

Full Screen

1{2 public function handle($request)3 {4 return 'handled';5 }6}7{8 public function handle($request)9 {10 return 'handled';11 }12}13{14 public function handle($request)15 {16 return 'handled';17 }18}19{20 public function handle($request)21 {22 return 'handled';23 }24}25{26 public function handle($request)27 {28 return 'handled';29 }30}31{32 public function handle($request)33 {34 return 'handled';35 }36}37{38 public function handle($request)39 {40 return 'handled';41 }42}43{44 public function handle($request)45 {46 return 'handled';47 }48}49{50 public function handle($request)51 {52 return 'handled';53 }54}55{56 public function handle($request)57 {58 return 'handled';59 }60}61{62 public function handle($request)63 {64 return 'handled';65 }66}67{68 public function handle($request)69 {70 return 'handled';71 }72}73{74 public function handle($request)75 {76 return 'handled';77 }78}79{

Full Screen

Full Screen

Kernel

Using AI Code Generation

copy

Full Screen

1$kernel = AspectMock::double('Kernel', ['getVersion' => 2]);2{3 public function getVersion()4 {5 return 1;6 }7}8{9 public function getVersion()10 {11 return 2;12 }13}14{15 public function getVersion()16 {17 return 3;18 }19}20{21 public function getVersion()22 {23 return 4;24 }25}26{27 public function getVersion()28 {29 return 5;30 }31}32{33 public function getVersion()34 {35 return 6;36 }37}38{39 public function getVersion()40 {41 return 7;42 }43}44{45 public function getVersion()46 {47 return 8;48 }49}50{51 public function getVersion()52 {53 return 9;54 }55}56{57 public function getVersion()58 {59 return 10;60 }61}62{63 public function getVersion()64 {65 return 11;66 }67}68{69 public function getVersion()70 {71 return 12;72 }73}74{75 public function getVersion()76 {77 return 13;78 }79}80{81 public function getVersion()82 {83 return 14;84 }85}86{87 public function getVersion()88 {89 return 15;90 }91}92{93 public function getVersion()94 {95 return 16;96 }97}98{99 public function getVersion()100 {101 return 17;102 }103}104{105 public function getVersion()106 {107 return 18;108 }109}110{

Full Screen

Full Screen

Kernel

Using AI Code Generation

copy

Full Screen

1use AspectMock\Test as test;2{3 public function testKernel()4 {5 $mock = test::double('Kernel', ['get' => 'value']);6 $this->assertEquals('value', $mock->get('test'));7 }8}9use AspectMock\Test as test;10{11 public function testKernel()12 {13 $mock = test::double('Kernel', ['get' => 'value']);14 $this->assertEquals('value', $mock->get('test'));15 }16}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run AspectMock automation tests on LambdaTest cloud grid

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

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful