Skip to content

Commit

Permalink
Update package and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed Mar 9, 2024
1 parent 08d6af9 commit 1c8ba57
Show file tree
Hide file tree
Showing 28 changed files with 224 additions and 175 deletions.
14 changes: 13 additions & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
github: danielsaidi
# These are supported funding model platforms

github: [danielsaidi]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
34 changes: 34 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This workflow builds and tests the project.
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift

name: Build Runner

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

env:
SCHEME: MockingKit

jobs:
build:
runs-on: macos-13
steps:
- uses: actions/checkout@v3
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '15.1.0'
- name: Build iOS
run: xcodebuild -scheme $SCHEME -derivedDataPath .build -destination 'generic/platform=iOS';
- name: Build macOS
run: xcodebuild -scheme $SCHEME -derivedDataPath .build -destination 'generic/platform=OS X';
- name: Build tvOS
run: xcodebuild -scheme $SCHEME -derivedDataPath .build -destination 'generic/platform=tvOS';
- name: Build watchOS
run: xcodebuild -scheme $SCHEME -derivedDataPath .build -destination 'generic/platform=watchOS';
- name: Build visionOS
run: xcodebuild -scheme $SCHEME -derivedDataPath .build -destination 'generic/platform=xrOS';
- name: Test iOS
run: xcodebuild test -scheme $SCHEME -derivedDataPath .build -destination 'platform=iOS Simulator,name=iPhone 15,OS=17.2' -enableCodeCoverage YES;
57 changes: 57 additions & 0 deletions .github/workflows/docc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# This workflow builds publish DocC docs to GitHub Pages.
# Source: https://maxxfrazer.medium.com/deploying-docc-with-github-actions-218c5ca6cad5
# Sample: https://github.com/AgoraIO-Community/VideoUIKit-iOS/blob/main/.github/workflows/deploy_docs.yml

name: DocC Runner

on:
push:
branches: ["main"]

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true

jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: macos-13
steps:
- name: Checkout
uses: actions/checkout@v3
- id: pages
name: Setup Pages
uses: actions/configure-pages@v4
- name: Select Xcode 15.1
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '15.1.0'
- name: Build DocC
run: |
swift package resolve;
xcodebuild docbuild -scheme MockingKit -derivedDataPath /tmp/docbuild -destination 'generic/platform=iOS';
$(xcrun --find docc) process-archive \
transform-for-static-hosting /tmp/docbuild/Build/Products/Debug-iphoneos/MockingKit.doccarchive \
--output-path docs \
--hosting-base-path 'MockingKit';
echo "<script>window.location.href += \"/documentation/mockingkit\"</script>" > docs/index.html;
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: 'docs'
- id: deployment
name: Deploy to GitHub Pages
uses: actions/deploy-pages@v4
81 changes: 24 additions & 57 deletions Fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,33 @@ default_platform :ios

platform :ios do

library_name = "MockingKit"
name = "MockingKit"
main_branch = "master"
build_folder_docs = ".build/docs"


# Build ==================

lane :build do |options|
platform = options[:platform]
sh("cd .. && xcodebuild -scheme " + name + " -derivedDataPath .build -destination 'generic/platform=" + platform + "';")
end


# Test ==================

lane :test_ios do
sh("cd .. && xcodebuild test -scheme " + name + " -derivedDataPath .build -destination 'platform=iOS Simulator,name=iPhone 15,OS=17.2' -enableCodeCoverage YES;")
end


# Version ================

desc "Create a new version"
lane :version do |options|
version_validate
docc

bump_type = options[:type]
version = version_bump_podspec(
path: 'Version',
bump_type: bump_type)

type = options[:type]
version = version_bump_podspec(path: 'Version', bump_type: type)
git_commit(path: "*", message: "Bump to #{version}")
add_git_tag(tag: version)
push_git_tags()
Expand All @@ -33,55 +43,12 @@ platform :ios do
ensure_git_status_clean
ensure_git_branch(branch: main_branch)
swiftlint(strict: true)
sh("swift test")
end


# Docs =======================

desc "Build documentation for all platforms"
lane :docc do
sh('cd .. && rm -rf ' + build_folder_docs)

docc_platform(destination: 'iOS', name: 'ios')
docc_platform(destination: 'OS X', name: 'osx')
docc_platform(destination: 'tvOS', name: 'tvos')
docc_platform(destination: 'watchOS', name: 'watchos')

docc_web_platform(name: 'ios')
docc_web_platform(name: 'osx')
docc_web_platform(name: 'tvos')
docc_web_platform(name: 'watchos')
end

desc "Build documentation for a single platform"
lane :docc_platform do |values|
sh('cd .. && mkdir -p ' + build_folder_docs)
docc_delete_derived_data(lib: library_name)
sh('cd .. && xcodebuild docbuild \
-scheme ' + library_name + ' \
-destination \'generic/platform=' + values[:destination] + '\'')
sh('cd .. && \
find ~/Library/Developer/Xcode/DerivedData \
-name "' + library_name + '.doccarchive" \
-exec cp -R {} ' + build_folder_docs + ' \;')
sh('cd .. && \
mv ' + build_folder_docs + '/' + library_name + '.doccarchive ' + build_folder_docs + '/' + library_name + '_' + values[:name] + '.doccarchive')
end

desc "Delete documentation derived data (may be historic duplicates)"
lane :docc_delete_derived_data do
sh('find ~/Library/Developer/Xcode/DerivedData \
-name "' + library_name + '.doccarchive" \
-exec rm -Rf {} \; || true')
end

desc "Build static documentation website for a single platform"
lane :docc_web_platform do |values|
sh('cd .. && $(xcrun --find docc) process-archive \
transform-for-static-hosting ' + build_folder_docs + '/' + library_name + '_' + values[:name] + '.doccarchive \
--output-path ' + build_folder_docs + '/web_' + values[:name] + ' \
--hosting-base-path ' + library_name + '')
build(platform: "iOS")
build(platform: "OS X")
build(platform: "tvOS")
build(platform: "watchOS")
build(platform: "xrOS")
test_ios
end

end
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Daniel Saidi
Copyright (c) 2019-2024 Daniel Saidi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
41 changes: 14 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
<p align="center">
<img src="https://img.shields.io/github/v/release/danielsaidi/MockingKit?color=%2300550&sort=semver" alt="Version" />
<img src="https://img.shields.io/badge/Swift-5.9-orange.svg" alt="Swift 5.9" />
<img src="https://img.shields.io/badge/platform-SwiftUI-blue.svg" alt="Swift UI" title="Swift UI" />
<img src="https://img.shields.io/github/license/danielsaidi/MockingKit" alt="MIT License" />
<a href="https://twitter.com/danielsaidi"><img src="https://img.shields.io/twitter/url?label=Twitter&style=social&url=https%3A%2F%2Ftwitter.com%2Fdanielsaidi" alt="Twitter: @danielsaidi" title="Twitter: @danielsaidi" /></a>
<a href="https://mastodon.social/@danielsaidi"><img src="https://img.shields.io/mastodon/follow/000253346?label=mastodon&style=social" alt="Mastodon: @danielsaidi@mastodon.social" title="Mastodon: @danielsaidi@mastodon.social" /></a>
</p>



## About MockingKit

MockingKit lets you mock protocols and classes in `Swift`. This is useful when unit testing, or to fake functionality that is not yet implemented.
MockingKit is a Swift SDK that lets you easily mock protocols and classes in `Swift`.

MockingKit lets you create mocks of any protocol or open class, after which you can `call` functions, `register` results, `record` method invocations, and `inspect` recorded calls.
MockingKit lets you create mocks of any protocol or class, after which you can `call` functions, `register` dynamic function results, automatically `record` method invocations, and `inspect` all recorded calls.

MockingKit doesn't require any setup or build scripts, and puts no restrictions on your code or architecture. Just create a mock and you're good to go.

Expand All @@ -30,8 +30,6 @@ MockingKit can be installed with the Swift Package Manager:
https://github.com/danielsaidi/MockingKit.git
```

If you prefer to not have external dependencies, you can also just copy the source code into your app.



## Getting started
Expand Down Expand Up @@ -78,26 +76,9 @@ let result = mock.doStuff(int: 42, string: "string") // => "gnirts"

// You can now inspect calls made to doStuff
let calls = mock.calls(to: \.doStuffRef) // => 1 item
calls[0].arguments.0 // => 42
calls[0].arguments.1 // => "string"
calls[0].arguments // => (42, "string")
calls[0].result // => "gnirts"
mock.hasCalled(\.doStuffRef) // => true
mock.hasCalled(\.doStuffRef, numberOfTimes: 1) // => true
mock.hasCalled(\.doStuffRef, numberOfTimes: 2) // => false
```

To mock a class, you just have to subclass the class and implement the `Mockable` protocol:

```swift
import MockingKit

class MockUserDefaults: UserDefaults, Mockable {

// You must provide a mock when implementing Mockable
var mock = Mock()

// You can now create lazy references just like in the protocol mock above
}
```

For more information, please see the [getting started guide][Getting-Started].
Expand All @@ -106,19 +87,22 @@ For more information, please see the [getting started guide][Getting-Started].

## Documentation

The [online documentation][Documentation] has more information, code examples, etc.
The [online documentation][Documentation] has more information, articles, code examples, etc.



## Demo Application

The demo app lets you explore the library on iOS and macOS. To try it out, just open and run the `Demo` project.
The demo app lets you explore the library. To try it out, just open and run the `Demo` project.



## Support my work

You can [sponsor me][Sponsors] on GitHub Sponsors or [reach out][Email] for paid support, to help support my [open-source projects][GitHub].
You can [sponsor me][Sponsors] on GitHub Sponsors or [reach out][Email] for paid support, to help support my [open-source projects][OpenSource].

Your support makes it possible for me to put more work into these projects and make them the best they can be.




Expand All @@ -140,12 +124,15 @@ MockingKit is available under the MIT license. See the [LICENSE][License] file f


[Email]: mailto:daniel.saidi@gmail.com

[Website]: https://www.danielsaidi.com
[GitHub]: https://www.github.com/danielsaidi
[Twitter]: https://www.twitter.com/danielsaidi
[Mastodon]: https://mastodon.social/@danielsaidi
[OpenSource]: https://danielsaidi.com/opensource
[Sponsors]: https://github.com/sponsors/danielsaidi

[Documentation]: https://danielsaidi.github.io/MockingKit/documentation/mockingkit/
[Documentation]: https://danielsaidi.github.io/MockingKit
[Getting-Started]: https://danielsaidi.github.io/MockingKit/documentation/mockingkit/getting-started

[License]: https://github.com/danielsaidi/MockingKit/blob/master/LICENSE
2 changes: 1 addition & 1 deletion Sources/MockingKit/AsyncMockReference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MockingKit
//
// Created by Tobias Boogh on 2022-05-04.
// Copyright © 2022 Daniel Saidi. All rights reserved.
// Copyright © 2022-2024 Daniel Saidi. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/MockingKit/Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MockingKit
//
// Created by Daniel Saidi on 2019-04-16.
// Copyright © 2019 Daniel Saidi. All rights reserved.
// Copyright © 2019-2024 Daniel Saidi. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/MockingKit/MockCall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MockingKit
//
// Created by Daniel Saidi on 2019-11-11.
// Copyright © 2019 Daniel Saidi. All rights reserved.
// Copyright © 2019-2024 Daniel Saidi. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/MockingKit/MockReference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MockingKit
//
// Created by Daniel Saidi on 2020-07-16.
// Copyright © 2020 Daniel Saidi. All rights reserved.
// Copyright © 2020-2024 Daniel Saidi. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/MockingKit/Mockable+Call.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MockingKit
//
// Created by Daniel Saidi on 2019-11-25.
// Copyright © 2019 Daniel Saidi. All rights reserved.
// Copyright © 2019-2024 Daniel Saidi. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/MockingKit/Mockable+Inspect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MockingKit
//
// Created by Daniel Saidi on 2019-11-25.
// Copyright © 2019 Daniel Saidi. All rights reserved.
// Copyright © 2019-2024 Daniel Saidi. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/MockingKit/Mockable+Register.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MockingKit
//
// Created by Daniel Saidi on 2019-11-25.
// Copyright © 2019 Daniel Saidi. All rights reserved.
// Copyright © 2019-2024 Daniel Saidi. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/MockingKit/Mockable+Reset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// MockingKit
//
// Created by Daniel Saidi on 2019-11-25.
// Copyright © 2019 Daniel Saidi. All rights reserved.
// Copyright © 2019-2024 Daniel Saidi. All rights reserved.
//

import Foundation
Expand Down
Loading

0 comments on commit 1c8ba57

Please sign in to comment.